{"id":67661,"date":"2016-08-05T13:18:32","date_gmt":"2016-08-05T05:18:32","guid":{"rendered":"http:\/\/www.xiaoyebailong.com\/?p=67661"},"modified":"2016-08-05T13:18:32","modified_gmt":"2016-08-05T05:18:32","slug":"charindex%e5%87%bd%e6%95%b0%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"http:\/\/www.xiaoyebailong.com\/index.php\/2016\/08\/05\/67661.htm","title":{"rendered":"charindex\u51fd\u6570\u4ecb\u7ecd"},"content":{"rendered":"<p>charindex\u51fd\u6570\u4ecb\u7ecd<br \/>\n\u4e00\u3001\u8bed\u6cd5<br \/>\nCHARINDEX ( char1 ,string1 [ , start_location ] )<br \/>\n\u5982\u679c char1 \u6216 string1 \u4e4b\u4e00\u662f Unicode \u6570\u636e\u7c7b\u578b\uff08nvarchar \u6216 nchar\uff09\u800c\u53e6\u4e00\u4e2a\u4e0d\u662f\uff0c\u5219\u5c06\u53e6\u4e00\u4e2a\u8f6c\u6362\u4e3a Unicode \u6570\u636e\u7c7b\u578b\u3002CHARINDEX \u4e0d\u80fd\u4e0e text\u3001ntext \u548c image \u6570\u636e\u7c7b\u578b\u4e00\u8d77\u4f7f\u7528\u3002<br \/>\n\u5982\u679c char1 \u6216 string1 \u4e4b\u4e00\u4e3a NULL\uff0c\u5e76\u4e14\u6570\u636e\u5e93\u517c\u5bb9\u7ea7\u522b\u4e3a 70 \u6216\u66f4\u9ad8\uff0c\u5219 CHARINDEX \u5c06\u8fd4\u56de NULL\u3002\u5982\u679c\u6570\u636e\u5e93\u517c\u5bb9\u7ea7\u522b\u4e3a 65 \u6216\u66f4\u4f4e\uff0c\u5219 CHARINDEX \u5c06\u4ec5\u5728 char1 \u548c string1 \u90fd\u4e3a NULL \u65f6\u624d\u8fd4\u56de NULL \u503c\u3002<br \/>\n\u5982\u679c\u5728 char1 \u5185\u627e\u4e0d\u5230 string1\uff0c\u5219 CHARINDEX \u8fd4\u56de 0\u3002<br \/>\nchar1 \u4e00\u4e2a\u8868\u8fbe\u5f0f\uff0c\u5176\u4e2d\u5305\u542b\u8981\u67e5\u627e\u7684\u5b57\u7b26\u7684\u5e8f\u5217\u3002<br \/>\nstring1 \u4e00\u4e2a\u8868\u8fbe\u5f0f\uff0c\u901a\u5e38\u662f\u4e00\u4e2a\u4e3a\u6307\u5b9a\u5e8f\u5217\u641c\u7d22\u7684\u5217\u3002string1 \u5c5e\u4e8e\u5b57\u7b26\u4e32\u6570\u636e\u7c7b\u522b\u3002<br \/>\nstart_location \u5f00\u59cb\u5728 string1 \u4e2d\u641c\u7d22 char1 \u65f6\u7684\u5b57\u7b26\u4f4d\u7f6e\u3002<br \/>\n\u5982\u679c start_location \u672a\u88ab\u6307\u5b9a\u3001\u662f\u4e00\u4e2a\u8d1f\u6570\u6216\u96f6\uff0c\u5219\u5c06\u4ece string1 \u7684\u5f00\u5934\u5f00\u59cb\u641c\u7d22\u3002start_location \u53ef\u4ee5\u662f bigint \u7c7b\u578b\u3002<br \/>\nstring1 \u4e2d\u5305\u542b char1 \u65f6\u8fd4\u56de\u5b57\u7b26\u4f4d\u7f6e<br \/>\nstring1 \u4e2d\u4e0d\u5305\u542b char1 \u65f6\u8fd4\u56de0<br \/>\n\u4e8c\u3001\u4e3e\u4f8b<br \/>\nUSE AdventureWorks<br \/>\nSELECT CHARINDEX(&#8216;bicycle&#8217;, DocumentSummary)<br \/>\nFROM Production.Document<br \/>\nWHERE DocumentID = 3;<br \/>\n\u8fd4\u56de\u7ed3\u679c\u4e3a48\u3002<br \/>\nSELECT CHARINDEX(&#8216;bicycle1&#8242;, DocumentSummary, 5)<br \/>\nFROM Production.Document<br \/>\nWHERE DocumentID = 3;<br \/>\n\u8fd4\u56de\u7ed3\u679c\u4e3a0\u3002<br \/>\n\u67e5\u8be2DocumentSummary\u5b57\u6bb5\u4e2d\u5305\u542b&#8221;bicycle&#8221;\u7684\u6240\u6709\u884c\u3002<br \/>\n\u4e00\u822c\u5927\u5bb6\u90fd\u4f1a\u5199\u6210\u8fd9\u6837:<br \/>\nselect * from Production.Document<br \/>\nwhere DocumentSummary like&#8217;%bicycle%&#8217;<br \/>\n\u4e86\u89e3\u8fd9\u4e2a\u51fd\u6570\u4ee5\u540e,\u5927\u5bb6\u53ef\u4ee5\u8fd9\u6837\u5199:<br \/>\nselect * from Production.Document<br \/>\nwhere charindex(&#8216;bicycle&#8217;,DocumentSummary)&gt;0<br \/>\n\u8fd9\u79cd\u65b9\u6cd5\u6bd4like&#8217;%%&#8217;\u7684\u5f62\u5f0f\u901f\u5ea6\u4e0a\u8981\u5feb\u5f88\u591a.<br \/>\n\u6570\u636e\u5e93\u4f18\u5316\u7684\u65f6\u5019\u53ef\u4ee5\u8003\u8651\u4f7f\u7528sql 2005\u7684\u51fd\u6570.<\/p>\n<p>&nbsp;<\/p>\n<p>\u4f8b\u5982\uff1asql=sql&amp;&#8221; charindex(&#8216;\u4ef7\u683c&#8217;,content)&gt;0 order by id desc&#8221;<\/p>\n<p>\u5927\u7ea60\u8868\u793a\u5305\u542b<\/p>\n<p>\u53cd\u4e4b\u5c0f\u4e8e\u7b49\u4e8e0<\/p>\n<p>\u5c31\u662f\u4e0d\u663e\u793a\u5305\u542b\u7684<\/p>\n<p>sql=sql&amp;&#8221; charindex(&#8216;\u4ef7\u683c&#8217;,content)&lt;=0 order by id desc&#8221;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>charindex\u51fd\u6570\u4ecb\u7ecd \u4e00\u3001\u8bed\u6cd5 CHARINDEX ( char1 ,string1 [ , start_location ] ) \u5982\u679c char1 \u6216 string1 \u4e4b\u4e00\u662f Unicode \u6570\u636e\u7c7b\u578b\uff08nvarchar \u6216 ncha&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,1],"tags":[227,106,228],"topic":[],"class_list":["post-67661","post","type-post","status-publish","format-standard","hentry","category-htmlcss","category-technology","tag-charindex","tag-sql","tag-228"],"_links":{"self":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/67661","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/comments?post=67661"}],"version-history":[{"count":1,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/67661\/revisions"}],"predecessor-version":[{"id":67662,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/67661\/revisions\/67662"}],"wp:attachment":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/media?parent=67661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/categories?post=67661"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/tags?post=67661"},{"taxonomy":"topic","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/topic?post=67661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}