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 執行
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 芭樂養樂多 的頭像
    芭樂養樂多

    隨手筆記

    芭樂養樂多 發表在 痞客邦 留言(0) 人氣()