{"id":1856,"date":"2011-07-18T12:14:56","date_gmt":"2011-07-18T04:14:56","guid":{"rendered":"http:\/\/jason695.why3s.tw\/wordpress\/?p=1856"},"modified":"2011-09-06T15:32:06","modified_gmt":"2011-09-06T07:32:06","slug":"sql-server-cursor-%e7%b0%a1%e5%96%ae%e7%af%84%e4%be%8b","status":"publish","type":"post","link":"https:\/\/jason695.why3s.tw\/wordpress\/2011\/07\/18\/sql-server-cursor-%e7%b0%a1%e5%96%ae%e7%af%84%e4%be%8b\/","title":{"rendered":"[\u8f49\u8cbc]SQL SERVER&#8211;cursor \u7c21\u55ae\u7bc4\u4f8b"},"content":{"rendered":"<p><a href=\"http:\/\/pgtalk.blogspot.com\/2007\/11\/sql-server-cursor.html\" target=\"_blank\">http:\/\/pgtalk.blogspot.com\/2007\/11\/sql-server-cursor.html<\/a><\/p>\n<p><code><br \/>\nUSE [testDB]<br \/>\nGO<br \/>\n\/****** \u7269\u4ef6: StoredProcedure [dbo].[pavo_CalculateRecordSum] \u6307\u4ee4\u78bc\u65e5\u671f: 11\/15\/2007 11:55:51 ******\/<br \/>\nSET ANSI_NULLS ON<br \/>\nGO<br \/>\nSET QUOTED_IDENTIFIER ON<br \/>\nGO<\/code><\/p>\n<p>CREATE PROCEDURE [dbo].[sp_cursor_Test]<br \/>\nAS<br \/>\nBEGIN<br \/>\nBEGIN TRY<br \/>\nBEGIN TRANSACTION<br \/>\nSET NOCOUNT ON;<br \/>\nDECLARE Cur Cursor FOR<br \/>\nSELECT a,b,c<br \/>\nFROM Table_A<br \/>\n&#8211;\u958b\u555fcursor<br \/>\nOpen Cur<\/p>\n<p>&#8211;\u5b9a\u7fa9cursor\u88e1\u8981\u53d6\u51fa\u7684\u7269\u4ef6<br \/>\nDECLARE @a int,@b nvarchar(50), @c DATETIME<\/p>\n<p>&#8211;\u9032\u5165cursor<br \/>\nFetch NEXT FROM Cur INTO @a, @b,@c<br \/>\nprint @@FETCH_STATUS;<br \/>\nWhile (@@FETCH_STATUS &lt;&gt; -1)<br \/>\nBEGIN<br \/>\n&#8211;\u5728\u6b64\u52a0\u5165LOOP\u4e2d\u7684\u5167\u5bb9<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p>&#8211;\u518d\u5230\u4e0b\u500b\u6307\u6a19\u53bb<br \/>\nFetch NEXT FROM Cur INTO @a, @b,@c<br \/>\nEND<\/p>\n<p>&#8211;\u95dc\u9589cursor<br \/>\nCLOSE Cur<br \/>\n&#8211;\u91cb\u653ecursor<br \/>\nDEALLOCATE Cur<\/p>\n<p>COMMIT TRANSACTION;<br \/>\nEND TRY<br \/>\nBEGIN CATCH<br \/>\n&#8211;\u5370\u51fa\u932f\u8aa4\u8a0a\u606f<br \/>\nPRINT ERROR_NUMBER();<br \/>\nPRINT ERROR_MESSAGE();<br \/>\nROLLBACK TRANSACTION;<br \/>\n&#8211;\u95dc\u9589cursor<br \/>\nCLOSE Cur<br \/>\n&#8211;\u91cb\u653ecursor<br \/>\nDEALLOCATE Cur<br \/>\nEND CATCH;<br \/>\nEND<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>http:\/\/pgtalk.blogspot.com\/2007\/11\/sql-server-cursor.ht &hellip; <a href=\"https:\/\/jason695.why3s.tw\/wordpress\/2011\/07\/18\/sql-server-cursor-%e7%b0%a1%e5%96%ae%e7%af%84%e4%be%8b\/\" class=\"more-link\">\u95b1\u8b80\u5168\u6587 <span class=\"screen-reader-text\">[\u8f49\u8cbc]SQL SERVER&#8211;cursor \u7c21\u55ae\u7bc4\u4f8b<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[47],"tags":[],"class_list":["post-1856","post","type-post","status-publish","format-standard","hentry","category-sql-server","no-featured-image"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/posts\/1856","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/comments?post=1856"}],"version-history":[{"count":0,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/posts\/1856\/revisions"}],"wp:attachment":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/media?parent=1856"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/categories?post=1856"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/tags?post=1856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}