close
set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go Create Proc [dbo].[usp_test] As Declare rs Cursor For (select top 10 taxcode from test_table) declare @str nvarchar(100) declare @result nvarchar(255) set @result = '' Open rs Fetch NEXT From rs into @str--將值放入變數 while @@Fetch_Status = 0--有回傳值 Begin set @result = @result + ',' + @str Fetch NEXT From rs into @str --將值放入變數 END close rs --關閉Cursor Deallocate rs --釋放Cursor select @result --exec usp_test 執行
全站熱搜