alter function F_GetUserPostion(@userName varchar(120)) returns varchar(600)
as
begin
Declare curGetUserPostion Cursor
for
select (select column_Name from Hr_Professional where Column_id=Hr_Intention.GSsortID) from Hr_Intention where GuserName=@userName
Declare @ColumnName varchar(120)
Declare @body varchar(600)
--初始化
Set @body=''
set @ColumnName=''
--打開游標
Open curGetUserPostion
--循環并提取記錄
Fetch Next From curGetUserPostion Into @ColumnName
While ( @@Fetch_Status=0 )
begin
--更新到匯總表。
set @body = @body+'-'+@ColumnName
Fetch Next From curGetUserPostion Into @ColumnName
end
--關閉游標
Close curGetUserPostion
--釋放游標
Deallocate curGetUserPostion
return @body
end
文章來源:http://www.cnblogs.com/wangdetian168/archive/2008/12/17/1356848.html