Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Creating Functions

Author  Topic 

Axxib
Starting Member

6 Posts

Posted - 2007-10-31 : 10:53:37
Can someone please explain what the following function does?


Use Master

go

create function dbo.concatenate(@a1 as int)
returns varchar(8000)
as
begin
declare @r varchar(8000)
declare @b1 varchar(1000)
set @r = ''
declare c cursor for
select Notes from heatdb..Accs where ID = @a1

open c

fetch next from c into @b1
while @@FETCH_STATUS = 0
begin
set @r = @r + ' ' + @b1
fetch next from c into @b1
end

close c
deallocate c

return @r
end
go

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2007-10-31 : 10:58:59
it goes your table 'Accs' and pulls out all the 'notes' entries for a given id (@a1), then concatenates them together into 1 string and returns it to you

Em
Go to Top of Page

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2007-10-31 : 10:59:26
Yes it contatenates values from Accs for a specified id

"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-10-31 : 11:01:43
basically it is implementing Rowset string concatenation


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Axxib
Starting Member

6 Posts

Posted - 2007-11-01 : 08:10:17
Thanks Guys
Go to Top of Page
   

- Advertisement -