{"id":648,"date":"2018-06-24T22:16:04","date_gmt":"2018-06-24T14:16:04","guid":{"rendered":"https:\/\/blog.freesilo.com\/?p=648"},"modified":"2018-06-24T22:16:04","modified_gmt":"2018-06-24T14:16:04","slug":"sql%e5%b0%86%e4%bb%a5%e5%ad%97%e7%ac%a6%e5%88%86%e9%9a%94%e7%9a%84%e5%ad%97%e6%ae%b5%e5%80%bc%ef%bc%8c%e5%be%aa%e7%8e%af%e6%8f%92%e5%85%a5%e8%a1%a8%e4%b8%ad","status":"publish","type":"post","link":"https:\/\/freesilo.com\/?p=648","title":{"rendered":"SQL\u5c06\u4ee5\u5b57\u7b26&#8217;,&#8217;\u5206\u9694\u7684\u5b57\u6bb5\u503c\uff0c\u5faa\u73af\u63d2\u5165\u8868\u4e2d"},"content":{"rendered":"<p>declare @strChatRooms nvarchar(1000) &#8211;\u81ea\u5b9a\u4e49\u53c2\u6570\uff0c\u542b\u6709&#8217;,&#8217;\u7b26\u53f7\u7684\u503c<br \/>\ndeclare @UserID int &#8211;\u81ea\u5b9a\u4e49\u53c2\u6570<br \/>\ndeclare @tmpNum int &#8211;\u68c0\u67e5&#8217;,&#8217;\u5b57\u7b26\uff0c\u79fb\u52a8\u7684\u4f4d\u7f6e<br \/>\ndeclare @tmpID int &#8211;\u83b7\u53d6\u5206\u9694\u7684\u503c\uff0c\u7528\u4e8e\u63d2\u5165\u8868<br \/>\ndeclare @iSuccess int &#8211;\u8fd4\u56de\u67e5\u770b\u9519\u8bef<\/p>\n<p>Begin Tran<br \/>\n&#8211;\u4e8b\u4f8b\u5b57\u7b26\u4e32<br \/>\nset @strChatRooms = &#8216;11,12,13,14,15,&#8217;<br \/>\n&#8211;\u521d\u59cb\u5316\u68c0\u67e5&#8217;,&#8217;\u7b26\u53f7\u4f4d\u7f6e\uff0c\u7b26\u53f7\u81ea\u5b9a\u4e49<br \/>\nset @tmpNum=1<br \/>\n&#8211;\u8fdb\u884c\u5faa\u73af\u5c06&#8217;,&#8217;\u7b26\u53f7\u5206\u9694\u7684\u6570\u636e\u63d2\u5165\u4fe1\u606f\u8868<br \/>\nwhile len(@strChatRooms) &gt; 0<br \/>\nbegin<br \/>\nif substring(@strChatRooms,@tmpNum,1) = &#8216;,&#8217;<br \/>\nbegin<br \/>\nset @tmpID=cast(left(@strChatRooms,@tmpNum-1) as int)<br \/>\nset @strChatRooms=right(@strChatRooms,len(@strChatRooms)-@tmpNum)<br \/>\nset @tmpNum=1<br \/>\nInsert into ChatAdmin(UserID,ChatRoomID)Values(@UserID,@tmpID)<br \/>\nif @@error &lt;&gt; 0<br \/>\nbegin<br \/>\nROLLBACK TRAN<br \/>\nset @iSuccess = -14<br \/>\nreturn<br \/>\nend<br \/>\nend<br \/>\nelse<br \/>\nset @tmpNum=@tmpNum+1<br \/>\nend<br \/>\nCommit Tran<\/p>\n","protected":false},"excerpt":{"rendered":"<p>declare @strChatRooms nvarchar(1000) &#038;#8&#8230;<br \/><a class=\"read-more-button\" href=\"https:\/\/freesilo.com\/?p=648\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-648","post","type-post","status-publish","format-standard","hentry","category-sql"],"_links":{"self":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/648","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=648"}],"version-history":[{"count":2,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/648\/revisions"}],"predecessor-version":[{"id":888,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/648\/revisions\/888"}],"wp:attachment":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=648"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=648"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}