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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Function Help

Author  Topic 

tooba
Posting Yak Master

224 Posts

Posted - 2013-02-19 : 23:03:23
Hi Guys,

Here is my UDF

Create Function [dbo].[udf_GetValue](@PID int)


returns varchar(1000)
as

begin
Declare @Message varchar(1000)

Select @Message = Message
From tbMessage
Where PId = @PID


return isnull(@Message,'')


end

I want to know
Let say if there is two PID How i can get , seperate Messages
End Result should be

MESSAGE
MSG1,MSG2,MSG3,....

I know UDF return only one value.
ANy advise?

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-02-19 : 23:44:57
[code]begin
Declare @Message varchar(1000)

Select @Message = COALESCE(@message, ', ') + Message + ', '
From tbMessage
Where PId = @PID

return STUFF(isnull(@Message,''), 1,2,'')
end

SELECT dbo.udf_GetValue( IdValue)[/code]

--
Chandu
Go to Top of Page

tooba
Posting Yak Master

224 Posts

Posted - 2013-02-20 : 00:46:02
Awesome Bandi, Thank you for your help....
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-02-20 : 00:49:25
quote:
Originally posted by tooba

Awesome Bandi, Thank you for your help....


Welcome

--
Chandu
Go to Top of Page
   

- Advertisement -