﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-老茂</title><link>http://www.cppblog.com/maosher/</link><description /><language>zh-cn</language><lastBuildDate>Fri, 17 Apr 2026 23:43:25 GMT</lastBuildDate><pubDate>Fri, 17 Apr 2026 23:43:25 GMT</pubDate><ttl>60</ttl><item><title>我的 vim for golang </title><link>http://www.cppblog.com/maosher/archive/2015/07/01/211114.html</link><dc:creator>Brandon</dc:creator><author>Brandon</author><pubDate>Wed, 01 Jul 2015 08:33:00 GMT</pubDate><guid>http://www.cppblog.com/maosher/archive/2015/07/01/211114.html</guid><wfw:comment>http://www.cppblog.com/maosher/comments/211114.html</wfw:comment><comments>http://www.cppblog.com/maosher/archive/2015/07/01/211114.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/maosher/comments/commentRss/211114.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/maosher/services/trackbacks/211114.html</trackback:ping><description><![CDATA[<div><a href="/Files/maosher/vimrc.txt">/Files/maosher/vimrc.txt</a></div><div></div><img src ="http://www.cppblog.com/maosher/aggbug/211114.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/maosher/" target="_blank">Brandon</a> 2015-07-01 16:33 <a href="http://www.cppblog.com/maosher/archive/2015/07/01/211114.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>新手的时候碰到的预处理命令</title><link>http://www.cppblog.com/maosher/archive/2011/02/17/140191.html</link><dc:creator>Brandon</dc:creator><author>Brandon</author><pubDate>Wed, 16 Feb 2011 16:04:00 GMT</pubDate><guid>http://www.cppblog.com/maosher/archive/2011/02/17/140191.html</guid><wfw:comment>http://www.cppblog.com/maosher/comments/140191.html</wfw:comment><comments>http://www.cppblog.com/maosher/archive/2011/02/17/140191.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/maosher/comments/commentRss/140191.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/maosher/services/trackbacks/140191.html</trackback:ping><description><![CDATA[今天一个新同学来问一个典型的预处理的问题，我当年也碰到这样的问题，贴出来，让更多的人能直接搜到<br><br>
<h1>预处理命令</h1>
<hr>
<h2><a name="">#,## </a></h2>
<p># 和 ## 操作符是和<a href="mk:@MSITStore:E:\doc\C++%20语言参考.chm::/cppreference.com/preproc_details.html#define"><u><font color=#810081>#define</font></u></a>宏使用的. 使用# 使在#后的首个参数返回为一个带引号的字符串. 例如, 命令 </p>
<pre>    #define to_string( s ) # s
</pre>
<p>将会使编译器把以下命令 </p>
<pre>    cout &lt;&lt; to_string( Hello World! ) &lt;&lt; endl;
</pre>
<p>理解为 </p>
<pre>    cout &lt;&lt; "Hello World!" &lt;&lt; endl;
</pre>
<p>使用##连结##前后的内容. 例如, 命令 </p>
<pre>    #define concatenate( x, y ) x ## y
...
int xy = 10;
...
</pre>
<p>将会使编译器把 </p>
<pre>    cout &lt;&lt; concatenate( x, y ) &lt;&lt; endl;
</pre>
<p>解释为 </p>
<pre>    cout &lt;&lt; xy &lt;&lt; endl;
</pre>
<p>理所当然,将会在标准输出处显示'10'.</p>
<br><br>
<h2><a name=line>#line</a> </h2>
<em>语法:</em>
<table bgColor=#ccccff>
    <tbody>
        <tr>
            <td>
            <pre>  #line line_number "filename"
            </pre>
            </td>
        </tr>
    </tbody>
</table>
<p>#line命令是用于更改__LINE__ 和 __FILE__变量的值. 文件名是可选的. __LINE__ 和 __FILE__ 变量描述被读取的当前文件和行. 命令 </p>
<pre>    #line 10 "main.cpp"
</pre>
<p>更改行号为10,当前文件改为"main.cpp". <br><br><br></p>
<h2><a name=predefined>预定义变量</a> </h2>
<p><em>语法:</em>
<table bgColor=#ccccff>
    <tbody>
        <tr>
            <td>
            <pre>  __LINE__
            __FILE__
            __DATE__
            __TIME__
            _cplusplus
            __STDC__
            </pre>
            </td>
        </tr>
    </tbody>
</table>
</p>
<p>下列参数在不同的编译器可能会有所不同, 但是一般是可用的:
<ul>
    <li>__LINE__ 和 __FILE__ 变量表示正在处理的当前行和当前文件.
    <li>__DATE__ 变量表示当前日期,格式为<em>month/day/year</em>(月/日/年).
    <li>__TIME__ 变量描述当前的时间,格式为<em>hour:minute:second</em>(时:分:秒).
    <li>_cplusplus 变量只在编译一个C++程序时定义.
    <li>__STDC__ 变量在编译一个C程序时定义,编译C++时也有可能定义. </li>
</ul>
<br>
<img src ="http://www.cppblog.com/maosher/aggbug/140191.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/maosher/" target="_blank">Brandon</a> 2011-02-17 00:04 <a href="http://www.cppblog.com/maosher/archive/2011/02/17/140191.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>介绍一个文件恢复工具</title><link>http://www.cppblog.com/maosher/archive/2011/02/16/140190.html</link><dc:creator>Brandon</dc:creator><author>Brandon</author><pubDate>Wed, 16 Feb 2011 15:56:00 GMT</pubDate><guid>http://www.cppblog.com/maosher/archive/2011/02/16/140190.html</guid><wfw:comment>http://www.cppblog.com/maosher/comments/140190.html</wfw:comment><comments>http://www.cppblog.com/maosher/archive/2011/02/16/140190.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/maosher/comments/commentRss/140190.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/maosher/services/trackbacks/140190.html</trackback:ping><description><![CDATA[<p>今天同学的u盘读不出数据来了，提示未格式化，在线搜了一</p>
<p>下，找到一个名叫winhex的工具。挺好用的，大家有这样的</p>
<p>问题的时候可以用一下。<br>猜想一下winhex的恢复指定类型文件工作原理<br>struct stBitMap<br>{<br>&nbsp;uint fileType;<br>&nbsp;uint ver;<br>&nbsp;uint size;<br>&nbsp;uint createDate;&nbsp;<br>}</p>
<p>假如上面是一个位图的文件结构头部分，那么winhex逐步扫</p>
<p>描文件块比较 和这个结构里比较</p>
<img src ="http://www.cppblog.com/maosher/aggbug/140190.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/maosher/" target="_blank">Brandon</a> 2011-02-16 23:56 <a href="http://www.cppblog.com/maosher/archive/2011/02/16/140190.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>好吧，我被征服了—— 关于 c++ unsigned char </title><link>http://www.cppblog.com/maosher/archive/2011/02/13/139977.html</link><dc:creator>Brandon</dc:creator><author>Brandon</author><pubDate>Sun, 13 Feb 2011 08:12:00 GMT</pubDate><guid>http://www.cppblog.com/maosher/archive/2011/02/13/139977.html</guid><wfw:comment>http://www.cppblog.com/maosher/comments/139977.html</wfw:comment><comments>http://www.cppblog.com/maosher/archive/2011/02/13/139977.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/maosher/comments/commentRss/139977.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/maosher/services/trackbacks/139977.html</trackback:ping><description><![CDATA[<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #008080;">1</span>&nbsp;<span style="color: #000000;">unsigned&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;i;<br></span><span style="color: #008080;">2</span>&nbsp;<span style="color: #000000;">i</span><span style="color: #000000;">=-</span><span style="color: #000000;">20</span><span style="color: #000000;">;<br></span><span style="color: #008080;">3</span>&nbsp;<span style="color: #000000;"></span></div>
上面一段很简单的代码，如果输出会是什么 呢？<br>今天群里的新学c++同学问我，unsighed char 和char 有啥区别，上面的输出会有什么 不同<br>在这里，我先鄙视一下自己，我直观的理解为通常的 首位符号位，然后丢下的就是输入无符号的。好吧，估计各位看官说我太菜，但确实是输出的结果和我想的不大一样，如果各位没明白我说的是什么问题，可以试一下。然后回来看下面的内容。<br><br><br><br><br><br><br><br><br><br><br><br><br>。<br>
<p class="docText">In an <tt>unsigned</tt> type, all the bits represent the value.
If a type is defined for a particular machine to use 8 bits, then the
<tt>unsigned</tt> version of this type could hold the values 0 through 255.</p>
<p class="docText">无符号型中，所有的位都表示数值。如果在某种机器中，定义一种类型使用 8 位表示，那么这种类型的
<tt>unsigned</tt> 型可以取值 0 到 255。</p>
<p class="docText">The C++ standard does not define how <tt>signed</tt> types are
represented at the bit level. Instead, each compiler is free to decide how it
will represent <tt>signed</tt> types. These representations can affect the range
of values that a <tt>signed</tt> type can hold. We are guaranteed that an 8-bit
<tt>signed</tt> type will hold at least the values from 127 through 127; many
implementations allow values from 128 through 127.</p>
<p class="docText">C++ 标准并未定义 <tt>signed</tt> 类型如何用位来表示，而是由每个编译器自由决定如何表示
<tt>signed</tt> 类型。这些表示方式会影响 <tt>signed</tt> 类型的取值范围。8 位 <tt>signed</tt>
类型的取值肯定至少是从 -127 到 127，但也有许多实现允许取值从 -128 到 127。</p>
<p class="docText">Under the most common strategy for representing <tt>signed</tt>
integral types, we can view one of the bits as a sign bit. Whenever the sign bit
is 1, the value is negative; when it is 0, the value is either 0 or a positive
number. An 8-bit integral <tt>signed</tt> type represented using a sign-bit can
hold values from 128 through 127.</p>
<p class="docText">表示 <tt>signed</tt> 整型类型最常见的策略是用其中一个位作为符号位。符号位为 1，值就为负数；符号位为
0，值就为 0 或正数。一个 <tt>signed</tt> 整型取值是从 -128 到 127。</p>
<a name="ch02lev3sec3"></a>
<h5 class="docSection3Title">Assignment to Integral Types</h5>
<h5 class="docSection3Title">整型的赋值</h5>
<a name="idd1e7331"></a><a name="idd1e7340"></a><a name="idd1e7349"></a><a name="idd1e7359"></a><a name="idd1e7369"></a><a name="idd1e7373"></a><a name="idd1e7380"></a><a name="idd1e7384"></a><a name="idd1e7387"></a><a name="idd1e7390"></a><a name="idd1e7394"></a><a name="idd1e7401"></a><a name="idd1e7413"></a>
<p class="docText">The type of an object determines the values that the object can
hold. This fact raises the question of what happens when one tries to assign a
value outside the allowable range to an object of a given type. The answer
depends on whether the type is <tt>signed</tt> or <tt>unsigned</tt>.</p>
<p class="docText">对象的类型决定对象的取值。这会引起一个疑问：当我们试着把一个超出其取值范围的值赋给一个指定类型的对象时，结果会怎样呢？答案取决于这种类型是
<tt>signed</tt> 还是 <tt>unsigned</tt> 的。</p>
<p class="docText">For <tt>unsigned</tt> types, the compiler <span class="docEmphasis">must</span> adjust the out-of-range value so that it will fit.
The compiler does so by taking the remainder of the value modulo the number of
distinct values the <tt>unsigned</tt> target type can hold. An object that is an
8-bit <tt>unsigned char</tt>, for example, can hold values from 0 through 255
inclusive. If we assign a value outside this range, the compiler actually
assigns the remainder of the value modulo 256. For example, we might attempt to
assign the value 336 to an 8-bit <tt>signed char</tt>. If we try to store 336 in
our 8-bit <tt>unsigned char</tt>, the actual value assigned will be 80, because
80 is equal to 336 modulo 256.</p>
<p class="docText">对于 <tt>unsigned</tt> 类型来说，编译器必须调整越界值使其满足要求。编译器会将该值对
<tt>unsigned</tt> 类型的可能取值数目求模，然后取所得值。比如 8 位的 <tt>unsigned char</tt>，其取值范围从 0 到
255（包括 255）。如果赋给超出这个范围的值，那么编译器将会取该值对 256 求模后的值。例如，如果试图将 336 存储到 8 位的
<tt>unsigned char</tt> 中，则实际赋值为 80，因为 80 是 336 对 256 求模后的值。</p>
<p class="docText">For the <tt>unsigned</tt> types, a negative value is always out
of range. An object of <tt>unsigned</tt> type may never hold a negative value.
Some languages make it illegal to assign a negative value to an
<tt>unsigned</tt> type, but C++ does not.</p>
<p class="docText">对于 <tt>unsigned</tt> 类型来说，负数总是超出其取值范围。<tt>unsigned</tt>
类型的对象可能永远不会保存负数。有些语言中将负数赋给 <tt>unsigned</tt> 类型是非法的，但在 C++ 中这是合法的。</p>
<a name="ch02note02"></a>
<div class="docNote">
<table style="width: 861px; height: 116px;" border="0" cellpadding="1" cellspacing="0">
    <tbody>
        <tr>
            <td valign="top" width="60"><br></td>
            <td valign="top">
            <p class="docText">In C++ it is perfectly legal to assign a negative number to an
            object with <tt>unsigned</tt> type. The result is the negative value modulo the
            size of the type. So, if we assign 1 to an 8-bit <tt>unsigned char</tt>, the
            resulting value will be 255, which is 1 modulo 256.</p>
            <p class="docText">C++ 中，把负值赋给 <tt>unsigned</tt>
            对象是完全合法的，其结果是该负数对该类型的取值个数求模后的值。所以，如果把 -1 赋给8位的 <tt>unsigned char</tt>，那么结果是
            255，因为 255 是 -1 对 256 求模后的值。</p>
            </td>
        </tr>
    </tbody>
</table>
<br></div>
<br>
<p class="docText">When assigning an out-of-range value to a <tt>signed</tt> type,
it is up to the compiler to decide what value to assign. In practice, many
compilers treat <tt>signed</tt> types similarly to how they are required to
treat <tt>unsigned</tt> types. That is, they do the assignment as the remainder
modulo the size of the type. However, we are not guaranteed that the compiler
will do so for the <tt>signed</tt> types.</p>
<p class="docText">当将超过取值范围的值赋给 <tt>signed</tt> 类型时，由编译器决定实际赋的值。在实际操作中，很多的编译器处理
<tt>signed</tt> 类型的方式和 <tt>unsigned</tt>
类型类似。也就是说，赋值时是取该值对该类型取值数目求模后的值。然而我们不能保证编译器都会这样处理 <tt>signed</tt> 类型。</p>
<p class="docText"><br></p>
<p class="docText"><br></p>
<p class="docText">以上摘自 c++ primer,惭愧，还是再细细的从头品一次这书吧。<br></p>
<p class="docText"></p>
<p class="docText"><br></p>
<br><br><br><br><br><br><br><img src ="http://www.cppblog.com/maosher/aggbug/139977.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/maosher/" target="_blank">Brandon</a> 2011-02-13 16:12 <a href="http://www.cppblog.com/maosher/archive/2011/02/13/139977.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>大家来看下这个sql语句</title><link>http://www.cppblog.com/maosher/archive/2010/10/25/131209.html</link><dc:creator>Brandon</dc:creator><author>Brandon</author><pubDate>Mon, 25 Oct 2010 08:41:00 GMT</pubDate><guid>http://www.cppblog.com/maosher/archive/2010/10/25/131209.html</guid><wfw:comment>http://www.cppblog.com/maosher/comments/131209.html</wfw:comment><comments>http://www.cppblog.com/maosher/archive/2010/10/25/131209.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/maosher/comments/commentRss/131209.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/maosher/services/trackbacks/131209.html</trackback:ping><description><![CDATA[<div style="background-color: rgb(238, 238, 238); font-size: 13px; border-left-color: rgb(204, 204, 204); padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; "><span style="color: #0000FF; ">IF</span><span style="color: #000000; ">&nbsp;(</span><span style="color: #008000; ">@ID</span><span style="color: #000000; ">&nbsp;</span><span style="color: #808080; ">NOT</span><span style="color: #000000; ">&nbsp;</span><span style="color: #808080; ">IN</span><span style="color: #000000; ">&nbsp;(</span><span style="color: #008000; ">@IDS</span><span style="color: #000000; ">))<br></span><span style="color: #0000FF; ">begin</span><span style="color: #000000; "><br></span><span style="color: #008080; ">--</span><span style="color: #008080; ">-do</span><span style="color: #008080; "><br></span><span style="color: #0000FF; ">end</span></div><div style="background-color: rgb(238, 238, 238); font-size: 13px; border-left-color: rgb(204, 204, 204); padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; "><span style="color: #0000FF; "><br></span></div><div style="background-color: rgb(238, 238, 238); font-size: 13px; border-left-color: rgb(204, 204, 204); padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; "><font  color="#0000FF">大部分时间我们用IN ，NOT IN在WHERE子句里，这样直接用好么，有什么问题，欢迎讨论</font></div><img src ="http://www.cppblog.com/maosher/aggbug/131209.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/maosher/" target="_blank">Brandon</a> 2010-10-25 16:41 <a href="http://www.cppblog.com/maosher/archive/2010/10/25/131209.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SQL字符串函数（二）</title><link>http://www.cppblog.com/maosher/archive/2010/10/22/130850.html</link><dc:creator>Brandon</dc:creator><author>Brandon</author><pubDate>Fri, 22 Oct 2010 00:32:00 GMT</pubDate><guid>http://www.cppblog.com/maosher/archive/2010/10/22/130850.html</guid><wfw:comment>http://www.cppblog.com/maosher/comments/130850.html</wfw:comment><comments>http://www.cppblog.com/maosher/archive/2010/10/22/130850.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/maosher/comments/commentRss/130850.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/maosher/services/trackbacks/130850.html</trackback:ping><description><![CDATA[<span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><strong>一、字符转换函数</strong></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">1、ASCII()</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">返回字符表达式最左端字符的ASCII 码值。在ASCII（）函数中，纯数字的字符串可不用&#8216;&#8217;括起来，但含其它字符的字符串必须用&#8216;&#8217;括起来使用，否则会出错。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">2、CHAR()</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">将ASCII 码转换为字符。如果没有输入0 ~ 255 之间的ASCII 码值，CHAR（） 返回NULL 。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">3、LOWER()和UPPER()</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">LOWER()将字符串全部转为小写；UPPER()将字符串全部转为大写。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">4、STR()</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">把数值型数据转换为字符型数据。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">STR (&lt;float_expression&gt;[，length[， &lt;decimal&gt;]])</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">length 指定返回的字符串的长度，decimal 指定返回的小数位数。如果没有指定长度，缺省的length 值为10， decimal 缺省值为0。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">当length 或者decimal 为负值时，返回NULL；</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">当length 小于小数点左边（包括符号位）的位数时，返回length 个*；</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">先服从length ，再取decimal ；</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">当返回的字符串位数小于length ，左边补足空格。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><strong>二、去空格函数</strong></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">1、LTRIM() 把字符串头部的空格去掉。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">2、RTRIM() 把字符串尾部的空格去掉。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><strong>三、取子串函数</strong></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">1、left()</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">&nbsp;</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">LEFT (&lt;character_expression&gt;， &lt;integer_expression&gt;)</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">返回character_expression 左起 integer_expression 个字符。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">2、RIGHT()</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">&nbsp;</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">RIGHT (&lt;character_expression&gt;， &lt;integer_expression&gt;)</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">返回character_expression 右起 integer_expression 个字符。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">3、SUBSTRING()</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">SUBSTRING (&lt;expression&gt;， &lt;starting_ position&gt;， length)</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">返回从字符串左边第starting_ position 个字符起length个字符的部分。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><strong>四、字符串比较函数</strong></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">1、CHARINDEX()</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">返回字符串中某个指定的子串出现的开始位置。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">CHARINDEX (&lt;&#8217;substring_expression&#8217;&gt;， &lt;expression&gt;)</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">其中substring _expression 是所要查找的字符表达式，expression 可为字符串也可为列名表达式。如果没有发现子串，则返回0 值。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">此函数不能用于TEXT 和IMAGE 数据类型。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">2、PATINDEX()</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">返回字符串中某个指定的子串出现的开始位置。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">PATINDEX (&lt;&#8217;%substring _expression%&#8217;&gt;， &lt;column_ name&gt;)其中子串表达式前后必须有百分号&#8220;%&#8221;否则返回值为0。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">与CHARINDEX 函数不同的是，PATINDEX函数的子串中可以使用通配符，且此函数可用于CHAR、 VARCHAR 和TEXT 数据类型。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><strong>五、字符串操作函数</strong></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">1、QUOTENAME()</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">返回被特定字符括起来的字符串。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">QUOTENAME (&lt;&#8217;character_expression&#8217;&gt;[， quote_ character]) 其中quote_ character 标明括字符串所用的字符，缺省值为&#8220;[]&#8221;。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">2、REPLICATE()</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">返回一个重复character_expression 指定次数的字符串。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">REPLICATE (character_expression integer_expression) 如果integer_expression 值为负值，则返回NULL 。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">3、REVERSE()</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">将指定的字符串的字符排列顺序颠倒。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">REVERSE (&lt;character_expression&gt;) 其中character_expression 可以是字符串、常数或一个列的值。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">4、REPLACE()</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">返回被替换了指定子串的字符串。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">REPLACE (&lt;string_expression1&gt;， &lt;string_expression2&gt;， &lt;string_expression3&gt;) 用string_expression3 替换在string_expression1 中的子串string_expression2。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">4、SPACE()</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">返回一个有指定长度的空白字符串。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">SPACE (&lt;integer_expression&gt;) 如果integer_expression 值为负值，则返回NULL 。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">5、STUFF()</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">用另一子串替换字符串指定位置、长度的子串。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">STUFF (&lt;character_expression1&gt;， &lt;start_ position&gt;， &lt;length&gt;，&lt;character_expression2&gt;)</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">如果起始位置为负或长度值为负，或者起始位置大于character_expression1 的长度，则返回NULL 值。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">如果length 长度大于character_expression1 中 start_ position 以右的长度，则character_expression1 只保留首字符。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><strong>六、数据类型转换函数</strong></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">1、CAST()</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">CAST (&lt;expression&gt; AS &lt;data_ type&gt;[ length ])</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">2、CONVERT()</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">CONVERT (&lt;data_ type&gt;[ length ]， &lt;expression&gt; [， style])</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">1）data_type为SQL Server系统定义的数据类型，用户自定义的数据类型不能在此使用。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">2）length用于指定数据的长度，缺省值为30。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">3）把CHAR或VARCHAR类型转换为诸如INT或SAMLLINT这样的INTEGER类型、结果必须是带正号或负号的数值。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">4）TEXT类型到CHAR或VARCHAR类型转换最多为8000个字符，即CHAR或VARCHAR数据类型是最大长度。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">5）IMAGE类型存储的数据转换到BINARY或VARBINARY类型，最多为8000个字符。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">6）把整数值转换为MONEY或SMALLMONEY类型，按定义的国家的货币单位来处理，如人民币、美元、英镑等。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">7）BIT类型的转换把非零值转换为1，并仍以BIT类型存储。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">8）试图转换到不同长度的数据类型，会截短转换值并在转换值后显示&#8220;+&#8221;，以标识发生了这种截断。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">9）用CONVERT（） 函数的style 选项能以不同的格式显示日期和时间。style 是将DATATIME 和SMALLDATETIME 数据转换为字符串时所选用的由SQL Server 系统提供的转换样式编号，不同的样式编号有不同的输出格式。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><strong>七、日期函数</strong></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">1、day(date_expression)</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">&nbsp;</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">返回date_expression中的日期值</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">2、month(date_expression)</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">返回date_expression中的月份值</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">3、year(date_expression)</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">返回date_expression中的年份值</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">4、DATEADD()</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">DATEADD (&lt;datepart&gt;， &lt;number&gt;， &lt;date&gt;)</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">返回指定日期date 加上指定的额外日期间隔number 产生的新日期。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">5、DATEDIFF()</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">DATEDIFF (&lt;datepart&gt;， &lt;date1&gt;， &lt;date2&gt;)</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">返回两个指定日期在datepart 方面的不同之处，即date2 超过date1的差距值，其结果值是一个带有正负号的整数值。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">6、DATENAME()</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">DATENAME (&lt;datepart&gt;， &lt;date&gt;)</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">以字符串的形式返回日期的指定部分此部分。由datepart 来指定。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">7、DATEPART()</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">DATEPART (&lt;datepart&gt;， &lt;date&gt;)</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">以整数值的形式返回日期的指定部分。此部分由datepart 来指定。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">DATEPART (dd， date) 等同于DAY (date)</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">DATEPART (mm， date) 等同于MONTH (date)</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">DATEPART (yy， date) 等同于YEAR (date)</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">8、GETDATE()</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; "><br></span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">以DATETIME 的缺省格式返回系统当前的日期和时间。</span><span  style="color: rgb(75, 75, 75); font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; ">&nbsp;</span>
<img src ="http://www.cppblog.com/maosher/aggbug/130850.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/maosher/" target="_blank">Brandon</a> 2010-10-22 08:32 <a href="http://www.cppblog.com/maosher/archive/2010/10/22/130850.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Sql字符串函数</title><link>http://www.cppblog.com/maosher/archive/2010/10/21/130776.html</link><dc:creator>Brandon</dc:creator><author>Brandon</author><pubDate>Thu, 21 Oct 2010 10:01:00 GMT</pubDate><guid>http://www.cppblog.com/maosher/archive/2010/10/21/130776.html</guid><wfw:comment>http://www.cppblog.com/maosher/comments/130776.html</wfw:comment><comments>http://www.cppblog.com/maosher/archive/2010/10/21/130776.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/maosher/comments/commentRss/130776.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/maosher/services/trackbacks/130776.html</trackback:ping><description><![CDATA[
<div><strong><span style="font-weight: normal; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 13px; line-height: 19px; "><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; text-indent: 0px; line-height: 1.5em; color: rgb(0, 0, 0); font-size: 13px; ">首先学习两个函数<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "></p>1.<strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">substring</strong>&nbsp; 返回字符、binary、text 或 image 表达式的一部分。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">基本语法:</strong>SUBSTRING&nbsp;<strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">(&nbsp;</strong><em style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">expression&nbsp;</em><strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">,</strong>&nbsp;<em style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">start&nbsp;</em><strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">,</strong>&nbsp;<em style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">length&nbsp;</em><strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">)&nbsp;</strong><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<em style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">expression</em>:字符串、二进制字符串、text、image、列或包含列的表达式<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<em style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">start</em>:整数，指定子串的开始位置&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(255, 0, 0); background-color: rgb(204, 255, 204); ">注:SQL中"1"表示字符串中的第一个字符,而.NET中"0"表示第一个字符</span><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<em style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">length</em>:整数，指定子串的长度（要返回的字符数或字节数）<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;2.<strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">patindex</strong>&nbsp;&nbsp;返回指定表达式中某模式第一次出现的起始位置；如果在全部有效的文本和字符数据类型中没有找到该模式，则返回零。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">基本语法:</strong>PATINDEX&nbsp;<strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">( '</strong><em style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">%pattern%</em><strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">' ,</strong>&nbsp;<em style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">expression&nbsp;</em><strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">)&nbsp;<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong><em style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">pattern:</em>字符串。可以使用通配符，但 pattern 之前和之后必须有 % 字符（搜索第一个和最后一个字符时除外）。pattern 是短字符数据类型类别的表达式<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><em style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expression</em>:表达式，通常为要在其中搜索指定模式的列，expression 为字符串数据类型</span></strong></div><div><strong><span style="font-weight: normal; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 13px; line-height: 19px; "><br></span></strong></div><div><strong><span style="font-weight: normal; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 13px; line-height: 19px; "><br></span></strong></div><div><strong><span style="font-weight: normal; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 13px; line-height: 19px; "><table id="Table1" class="tb" cellspacing="0" cellpadding="3" border="0" style="font-size: 13px; font-family: Simsun; line-height: normal; "><tbody><tr><td><pre><div><span style="color: rgb(0, 0, 255); ">declare</span><span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(0, 128, 0); ">@a</span><span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(0, 0, 0); font-weight: bold; ">varchar</span><span style="color: rgb(0, 0, 0); ">(</span><span style="color: rgb(128, 0, 0); font-weight: bold; ">50</span><span style="color: rgb(0, 0, 0); ">)
</span><span style="color: rgb(0, 0, 255); ">set</span><span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(0, 128, 0); ">@a</span><span style="color: rgb(128, 128, 128); ">=</span><span style="color: rgb(255, 0, 0); ">'</span><span style="color: rgb(255, 0, 0); ">2009年7月15日星期五</span><span style="color: rgb(255, 0, 0); ">'</span><span style="color: rgb(0, 0, 0); ">
</span><span style="color: rgb(0, 0, 255); ">select</span><span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(255, 0, 255); ">substring</span><span style="color: rgb(0, 0, 0); ">(</span><span style="color: rgb(0, 128, 0); ">@a</span><span style="color: rgb(0, 0, 0); ">,</span><span style="color: rgb(128, 0, 0); font-weight: bold; ">1</span><span style="color: rgb(0, 0, 0); ">,</span><span style="color: rgb(128, 0, 0); font-weight: bold; ">4</span><span style="color: rgb(0, 0, 0); ">) </span><span style="color: rgb(0, 128, 128); ">--</span><span style="color: rgb(0, 128, 128); ">获取年份2009</span><span style="color: rgb(0, 128, 128); ">
</span><span style="color: rgb(0, 0, 255); ">declare</span><span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(0, 128, 0); ">@b</span><span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(0, 0, 0); font-weight: bold; ">int</span><span style="color: rgb(0, 0, 0); ">
</span><span style="color: rgb(0, 0, 255); ">set</span><span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(0, 128, 0); ">@b</span><span style="color: rgb(128, 128, 128); ">=</span><span style="color: rgb(255, 0, 255); ">patindex</span><span style="color: rgb(0, 0, 0); ">(</span><span style="color: rgb(255, 0, 0); ">'</span><span style="color: rgb(255, 0, 0); ">%日%</span><span style="color: rgb(255, 0, 0); ">'</span><span style="color: rgb(0, 0, 0); ">,</span><span style="color: rgb(0, 128, 0); ">@a</span><span style="color: rgb(0, 0, 0); ">) </span><span style="color: rgb(0, 128, 128); ">--</span><span style="color: rgb(0, 128, 128); ">获取'日'这个字符在字符串中的位置,即10</span><span style="color: rgb(0, 128, 128); ">
</span><span style="color: rgb(0, 0, 255); ">select</span><span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(255, 0, 255); ">substring</span><span style="color: rgb(0, 0, 0); ">(</span><span style="color: rgb(0, 128, 0); ">@a</span><span style="color: rgb(0, 0, 0); ">,</span><span style="color: rgb(128, 0, 0); font-weight: bold; ">6</span><span style="color: rgb(0, 0, 0); ">,</span><span style="color: rgb(0, 128, 0); ">@b</span><span style="color: rgb(128, 128, 128); ">-</span><span style="color: rgb(128, 0, 0); font-weight: bold; ">5</span><span style="color: rgb(0, 0, 0); ">) </span><span style="color: rgb(0, 128, 128); ">--</span><span style="color: rgb(0, 128, 128); ">获取日期'7月15日'</span></div></pre></td></tr></tbody></table></span></strong></div><img src ="http://www.cppblog.com/maosher/aggbug/130776.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/maosher/" target="_blank">Brandon</a> 2010-10-21 18:01 <a href="http://www.cppblog.com/maosher/archive/2010/10/21/130776.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>AfxGetMainWnd()在线程里使用的问题</title><link>http://www.cppblog.com/maosher/archive/2010/08/26/124783.html</link><dc:creator>Brandon</dc:creator><author>Brandon</author><pubDate>Thu, 26 Aug 2010 03:08:00 GMT</pubDate><guid>http://www.cppblog.com/maosher/archive/2010/08/26/124783.html</guid><wfw:comment>http://www.cppblog.com/maosher/comments/124783.html</wfw:comment><comments>http://www.cppblog.com/maosher/archive/2010/08/26/124783.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/maosher/comments/commentRss/124783.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/maosher/services/trackbacks/124783.html</trackback:ping><description><![CDATA[<font size=1>AfxGetMainWnd()的使用依赖于线程<br>具体参加源代码<br><br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">&nbsp;1</span><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">_AFXWIN_INLINE&nbsp;CWnd</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;AFXAPI&nbsp;AfxGetMainWnd()<br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #000000"><img id=Codehighlighter1_44_142_Open_Image onclick="this.style.display='none'; Codehighlighter1_44_142_Open_Text.style.display='none'; Codehighlighter1_44_142_Closed_Image.style.display='inline'; Codehighlighter1_44_142_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_44_142_Closed_Image onclick="this.style.display='none'; Codehighlighter1_44_142_Closed_Text.style.display='none'; Codehighlighter1_44_142_Open_Image.style.display='inline'; Codehighlighter1_44_142_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_44_142_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_44_142_Open_Text><span style="COLOR: #000000">{&nbsp;CWinThread</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;pThread&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;AfxGetThread();<br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;pThread&nbsp;</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">&nbsp;NULL&nbsp;</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">&nbsp;pThread</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetMainWnd()&nbsp;:&nbsp;NULL;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;4</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br></span><span style="COLOR: #008080">&nbsp;5</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">而AfxGetThread获取的是当前线程，而不是主线程！</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">&nbsp;6</span><span style="COLOR: #008000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #000000">CWinThread</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;AFXAPI&nbsp;AfxGetThread()<br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #000000"><img id=Codehighlighter1_211_392_Open_Image onclick="this.style.display='none'; Codehighlighter1_211_392_Open_Text.style.display='none'; Codehighlighter1_211_392_Closed_Image.style.display='inline'; Codehighlighter1_211_392_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_211_392_Closed_Image onclick="this.style.display='none'; Codehighlighter1_211_392_Closed_Text.style.display='none'; Codehighlighter1_211_392_Open_Image.style.display='inline'; Codehighlighter1_211_392_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_211_392_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_211_392_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;check&nbsp;for&nbsp;current&nbsp;thread&nbsp;in&nbsp;module&nbsp;thread&nbsp;state</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #008000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #000000">AFX_MODULE_THREAD_STATE</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;pState&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;AfxGetModuleThreadState();<br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">CWinThread</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;pThread&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;pState</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">m_pCurrentWinThread;<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;pThread;<br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span></div>
</font>所以在非主线程里使用可能会有问题，解决方法，在新创建的线程里使用AfxGetApp()-&gt;m_pMainWnd;
<img src ="http://www.cppblog.com/maosher/aggbug/124783.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/maosher/" target="_blank">Brandon</a> 2010-08-26 11:08 <a href="http://www.cppblog.com/maosher/archive/2010/08/26/124783.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>游标</title><link>http://www.cppblog.com/maosher/archive/2010/08/11/123121.html</link><dc:creator>Brandon</dc:creator><author>Brandon</author><pubDate>Wed, 11 Aug 2010 15:22:00 GMT</pubDate><guid>http://www.cppblog.com/maosher/archive/2010/08/11/123121.html</guid><wfw:comment>http://www.cppblog.com/maosher/comments/123121.html</wfw:comment><comments>http://www.cppblog.com/maosher/archive/2010/08/11/123121.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/maosher/comments/commentRss/123121.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/maosher/services/trackbacks/123121.html</trackback:ping><description><![CDATA[使用游标类型执行的速度<br><br>adOpenForwardOnly &nbsp; &gt; &nbsp; adOpenDynamic &nbsp; &gt; &nbsp; adOpenKeyset &nbsp; &gt; &nbsp; adOpenStatic &nbsp; <br><br>游标类型有以下四种类型： <br>1、 &nbsp; AdOpenForwardOnly &nbsp; （默认值）一次只能向前移动一行。 <br>2、 &nbsp; AdOpenKeyset &nbsp; 打开键集类型游标。 <br>3、 &nbsp; AdOpenDynamic &nbsp; 打开动态类型游标 <br>4、 &nbsp; AdOpenStatic &nbsp; 打开静态类型游标。 <br>AdOpenForwardOnly和AdOpenStatic这两种游标使得记录集只读，它表示创建数据的一个快照。后者比前者灵活，因为它可以允许任意方向移动。 <br>AdOpenKeyset允许任意移动，并且允许更改记录集。其他用户对记录集的添加和删除，这个游标反映不出来。但它能反映出其他用户对记录集的更改。 <br>AdOpenDynamic允许所有操作，其他用户对记录集的添加、删除、更改在此记录集中 <br>都是可见的。 <br>LockType= &nbsp; adLockOptimistic <br>Options &nbsp; 省略 &nbsp; <br>大家需要注意的是：当使用AdOpenKeyset时，要求记录集中每条记录都有唯一的关键字。否则，执行的结果就不是您所要的所有记录了。 <br>清楚了游标类型，再来看看锁类型LockType <br>AdLockReadOnly &nbsp; （默认值）只读 &nbsp; --- &nbsp; 不能改变数据。 <br>AdLockPessimistic &nbsp; 悲观锁（逐个）--- &nbsp; 为确保成功完成编辑记录所需的工作， <br>在编辑时立即锁定数据源的记录。 <br>AdLockOptimistic &nbsp; 乐观锁（逐个）--- &nbsp; 只在调用Update &nbsp; 方法时才锁定记录。 <br>AdLockBatchOptimistic &nbsp; 乐观批更新---用于批更新模式（与立即更新模式相对）。 <br>对于悲观锁、乐观锁的解释： <br>乐观的锁策略是把记录必须加锁的时间减到最短，当用户对记录的内容进行编辑时，乐观锁不起作用，其他用户可以访问和编辑数据，但当其中的一个用户想要更新数据时，记录就会加上锁； <br>悲观的锁策略是当第一个用户打开记录进行编辑的时候，记录就会加锁，直到使用记录的用户解除锁时锁才不起作用。一旦悲观锁起作用，其他的用户就看不到数据，直到该锁被解除； <br>对于AdLockBatchOptimistic，只能与AdOpenKeyset游标一起使用。它在更新时不会立即把更新过的记录写入到数据源中，而是把对许多条记录所做的改动先放在客户计算机中，然后把更新过的记录作为一批写入数据源
<img src ="http://www.cppblog.com/maosher/aggbug/123121.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/maosher/" target="_blank">Brandon</a> 2010-08-11 23:22 <a href="http://www.cppblog.com/maosher/archive/2010/08/11/123121.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RadioButton</title><link>http://www.cppblog.com/maosher/archive/2010/07/26/121276.html</link><dc:creator>Brandon</dc:creator><author>Brandon</author><pubDate>Mon, 26 Jul 2010 00:19:00 GMT</pubDate><guid>http://www.cppblog.com/maosher/archive/2010/07/26/121276.html</guid><wfw:comment>http://www.cppblog.com/maosher/comments/121276.html</wfw:comment><comments>http://www.cppblog.com/maosher/archive/2010/07/26/121276.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/maosher/comments/commentRss/121276.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/maosher/services/trackbacks/121276.html</trackback:ping><description><![CDATA[<p>RadioButton的分组是按TabStop来分的，第一个Group为true 直到碰到下一个Group为true前，一直是一组</p>
<img src ="http://www.cppblog.com/maosher/aggbug/121276.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/maosher/" target="_blank">Brandon</a> 2010-07-26 08:19 <a href="http://www.cppblog.com/maosher/archive/2010/07/26/121276.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>