{"id":350,"date":"2023-09-16T10:44:54","date_gmt":"2023-09-16T02:44:54","guid":{"rendered":""},"modified":"2023-09-16T15:50:11","modified_gmt":"2023-09-16T07:50:11","slug":"sql-server%e4%b8%ad%e6%88%aa%e5%8f%96%e5%ad%97%e7%ac%a6%e4%b8%b2%e7%9a%84%e5%b8%b8%e7%94%a8%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/mushiming.com\/350.html","title":{"rendered":"sql server\u4e2d\u622a\u53d6\u5b57\u7b26\u4e32\u7684\u5e38\u7528\u51fd\u6570"},"content":{"rendered":"
sql server\u63d0\u4f9b\u4e863\u4e2a\u5e38\u7528\u622a\u53d6\u5b57\u7b26\u4e32\u65b9\u6cd5\uff0cLEFT()\u3001RIGHT()\u3001SUBSTRING()\uff0c\u8ddfC#\u4e0d\u540c\u7684\u662f\uff0c\u8d77\u59cb\u7b2c\u4e00\u4e2a\u7d22\u5f15\u4e3a1\u3002<\/p>\n
1.LEFT ( character_expression , integer_expression )\n\u51fd\u6570\u8bf4\u660e\uff1aLEFT ( '\u6e90\u5b57\u7b26\u4e32' , '\u8981\u622a\u53d6\u6700\u5de6\u8fb9\u7684\u5b57\u7b26\u6570' )\n\u8fd4\u56de\u4ece\u5b57\u7b26\u4e32\u5de6\u8fb9\u5f00\u59cb\u6307\u5b9a\u4e2a\u6570\u7684\u5b57\u7b26\nselect LEFT('SQL_Server_2008',4 );\n\u8fd4\u56de\u7ed3\u679c\uff1aSQL_\n \n \n2.RIGHT ( character_expression , integer_expression )\n\u51fd\u6570\u8bf4\u660e\uff1aRIGHT ( '\u6e90\u5b57\u7b26\u4e32' , '\u8981\u622a\u53d6\u6700\u53f3\u8fb9\u7684\u5b57\u7b26\u6570' )\n\u8fd4\u56de\u5b57\u7b26\u4e32\u4e2d\u4ece\u53f3\u8fb9\u5f00\u59cb\u6307\u5b9a\u4e2a\u6570\u7684 integer_expression \u5b57\u7b26\nselect RIGHT('SQL_Server_2008',4 );\n\u8fd4\u56de\u7ed3\u679c\uff1a2008\n \n \n3.SUBSTRING ( character_expression , start , length )\n\u51fd\u6570\u8bf4\u660e\uff1aSUBSTRING ( '\u6e90\u5b57\u7b26\u4e32' , '\u622a\u53d6\u8d77\u59cb\u4f4d\u7f6e(\u542b\u8be5\u4f4d\u7f6e\u4e0a\u7684\u5b57\u7b26)' , '\u622a\u53d6\u957f\u5ea6' )\n\u8fd4\u56de\u5b57\u7b26\u3001binary\u3001text \u6216 image \u8868\u8fbe\u5f0f\u7684\u4e00\u90e8\u5206\nselect SUBSTRING('SQL_Server_2008',5 ,6);\n\u8fd4\u56de\u7ed3\u679c\uff1aServer<\/code><\/pre>\n\u53cd\u9009reverse()\uff0c\u662f\u5c06\u5b57\u6bb5\u5185\u5bb9\u98a0\u5012\u6bd4\u5982:<\/p>\n
select reverse('SQL_Server_2012')\n\u8fd4\u56de\u7ed3\u679c\uff1a2102_revreS_LQS<\/code><\/pre>\n charindex()\u51fd\u6570\uff1a<\/strong><\/p>\n\u5199SQL\u8bed\u53e5\u6211\u4eec\u7ecf\u5e38\u9700\u8981\u5224\u65ad\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u662f\u5426\u5305\u542b\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u4f46\u662fSQL SERVER\u4e2d\u5e76\u6ca1\u6709\u50cfC#\u63d0\u4f9b\u4e86Contains\u51fd\u6570\uff0c\u4e0d\u8fc7SQL SERVER\u4e2d\u63d0\u4f9b\u4e86\u4e00\u4e2a\u53ebCHAEINDX\u7684\u51fd\u6570\uff0c\u987e\u540d\u601d\u4e49\u5c31\u662f\u627e\u5230\u5b57\u7b26\uff08char\uff09\u7684\u4f4d\u7f6e\uff08index\uff09\uff0c\u65e2\u7136\u80fd\u591f\u77e5\u9053\u6240\u5728\u7684\u4f4d\u7f6e\uff0c\u5f53\u7136\u5c31\u53ef\u4ee5\u5224\u65ad\u662f\u5426\u5305\u542b\u5728\u5176\u4e2d\u4e86\u3002<\/p>\n
\u901a\u8fc7CHARINDEX\u5982\u679c\u80fd\u591f\u627e\u5230\u5bf9\u5e94\u7684\u5b57\u7b26\u4e32\uff0c\u5219\u8fd4\u56de\u8be5\u5b57\u7b26\u4e32\u4f4d\u7f6e\uff0c\u5426\u5219\u8fd4\u56de0\u3002<\/p>\n
\u57fa\u672c\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n
\u3000\u3000CHARINDEX ( expressionToFind , expressionToSearch [ , start_location ] )<\/strong><\/p>\n expressionToFind \uff1a\u76ee\u6807\u5b57\u7b26\u4e32\uff0c\u5c31\u662f\u60f3\u8981\u627e\u5230\u7684\u5b57\u7b26\u4e32\uff0c\u6700\u5927\u957f\u5ea6\u4e3a8000 \u3002<\/p>\n
\u3000\u3000expressionToSearch \uff1a\u7528\u4e8e\u88ab\u67e5\u627e\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n
start_location\uff1a\u5f00\u59cb\u67e5\u627e\u7684\u4f4d\u7f6e\uff0c\u4e3a\u7a7a\u65f6\u9ed8\u8ba4\u4ece\u7b2c\u4e00\u4f4d\u5f00\u59cb\u67e5\u627e\u3002<\/p>\n
--\u5982\u679c\u6ca1\u6709\u67e5\u5230\uff0c\u5219\u8fd4\u56de\u7ed3\u679c\u4e3a0\n---\u5927\u5c0f\u5199\u654f\u611f\nselect charindex('S','sql_server_2008' COLLATE Latin1_General_CS_AS)\n\u8fd4\u56de\u7ed3\u679c\uff1a0\n\n--\u57fa\u672c\u7528\u6cd5\nselect charindex('s','sql_server_2008')\n--\u8fd4\u56de\u7ed3\u679c\uff1a1\n\n\nselect charindex('s','sql_server_2008',3)\n--\u8fd4\u56de\u7ed3\u679c\uff1a5<\/code><\/pre>\n\u5728\u622a\u53d6\u5b57\u7b26\u4e32\u4e2d\uff0c\u6839\u636e\u4e0d\u540c\u7684\u4e1a\u52a1\u9700\u6c42\uff0c\u53bb\u7ed3\u5408\u76f8\u5e94\u7684\u540e\u8fb9\u4e24\u4e2a\u51fd\u6570\uff0c\u57fa\u672c\u80fd\u5f97\u5230\u4f60\u60f3\u8981\u7684\u7ed3\u679c\u3002\u4ee3\u7801\u662f\u6b7b\u7684\uff0c\u601d\u60f3\u662f\u6d3b\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"sqlserver\u63d0\u4f9b\u4e863\u4e2a\u5e38\u7528\u622a\u53d6\u5b57\u7b26\u4e32\u65b9\u6cd5\uff0cLEFT()\u3001RIGHT()\u3001SUBSTRING()\uff0c\u8ddfC#\u4e0d\u540c\u7684\u662f\uff0c\u8d77\u59cb\u7b2c\u4e00\u4e2a\u7d22\u5f15\u4e3a1\u30021.LEFT(character...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/350"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=350"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/350\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=350"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=350"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}