{"id":1620,"date":"2011-03-22T00:58:25","date_gmt":"2011-03-22T00:58:25","guid":{"rendered":"http:\/\/enjoyasp.net\/?p=1620"},"modified":"2011-06-18T00:15:59","modified_gmt":"2011-06-18T00:15:59","slug":"sql%e7%9a%84%e5%90%8c%e6%97%b6%e6%93%8d%e4%bd%9c%e6%80%a7%ef%bc%8cselect%e5%88%97%e8%a1%a8%e4%b8%ad%e7%9a%84%e6%89%a7%e8%a1%8c%e9%a1%ba%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/enjoyasp.net\/index.php\/2011\/03\/22\/sql%e7%9a%84%e5%90%8c%e6%97%b6%e6%93%8d%e4%bd%9c%e6%80%a7%ef%bc%8cselect%e5%88%97%e8%a1%a8%e4%b8%ad%e7%9a%84%e6%89%a7%e8%a1%8c%e9%a1%ba%e5%ba%8f\/","title":{"rendered":"SQL\u7684\u540c\u65f6\u64cd\u4f5c\u6027\uff0cselect\u5217\u8868\u4e2d\u7684\u6267\u884c\u987a\u5e8f"},"content":{"rendered":"<pre escaped=\"true\" lang=\"tsql\">\r\n SQL\u4e2d\u7684\u591a\u4e2a\u8fd0\u7b97\u662f\u540c\u65f6\u8fdb\u884c\u8ba1\u7b97\u7684\uff0c\u5373\u540c\u65f6\u64cd\u4f5c\uff0call-at-once operation\uff0c\u4e0e\u5728select\u5217\u8868\u4e2d\u7684\u524d\u540e\u4f4d\u7f6e\u65e0\u5173\r\n\u5982\uff1a update a\r\n        set a.value1 = a.value2, a.value2 = a.value1  --\u540c\u65f6\u53d1\u751f\uff0c\u5373\u65f6\u4ea4\u6362\r\n        from tmpTable\r\n\u7531\u4e0a\u77e5\uff1a1\uff09select\u4e2d\u7684\u522b\u540d\u4e0d\u80fd\u5728\u540c\u4e00select\u5217\u8868\u4e2d\u4f7f\u7528\u3002 \u5982select max(id) mid, mid+1 from tmpTable \u662f\u9519\u8bef\u7684\r\n             2\uff09UPDATE t\r\n                  SET t.c4 = convert(varchar(20),GETDATE(),120)\r\n                  FROM tmp2 t\r\n                  \u56e0\u6267\u884c\u662f\u540c\u65f6\u8fdb\u884c\u7684\uff0c\u6545t.c4\u5f97\u5230\u7684\u65e5\u671f\u662f\u76f8\u540c\u7684\r\n             3\uff09update a set a.value1 = 100 + (select max(c1) from tmpTable)    \u56e0\u6267\u884c\u662f\u540c\u65f6\u7684\uff0c\u6545\u6700\u5927\u503cc1\u4e0d\u4f1a\u6539\u53d8\r\n\r\n4\uff09\u5e94\u7528\uff1a\u5f97\u5230\u67d0\u4e00\u503c\uff0c\u5e76\u5c06\u6b64\u503c\u52a01\r\n                  update a set @value = value, value = value+1 from tmpTable\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>SQL\u4e2d\u7684\u591a\u4e2a\u8fd0\u7b97\u662f\u540c\u65f6\u8fdb\u884c\u8ba1\u7b97\u7684\uff0c\u5373\u540c\u65f6\u64cd\u4f5c\uff0call-at-once operation\uff0c\u4e0e\u5728select\u5217 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-1620","post","type-post","status-publish","format-standard","hentry","category-sql-server"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/1620","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/comments?post=1620"}],"version-history":[{"count":0,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/1620\/revisions"}],"wp:attachment":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/media?parent=1620"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/categories?post=1620"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/tags?post=1620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}