.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Sql Server >> Post New QuestionBookmark and Share Subscribe to Forum

query / function to get the oupput

Posted By: Santosh     Posted Date: February 25, 2013    Points:5   Category :Sql Server
Hi
any one please give me a sql query as per below output.

Table Nme :
ID EmpId Name
1 2 Ram
1 6 San
1 8 Tap

if i pass the value EmpIDs = '2,8' , as per the Empid Name should be displayed with comma separated in same row.

Output :
ID Name
1 Ram,Tap

Thanks
Santosh

Responses
Author: Narayanan             
Posted Date: February 28, 2013     Points: 20   

Hi ,
  alter FUNCTION [dbo].[GetAliasesById]
(
@userID int
)
RETURNS varchar(max)
AS
BEGIN
declare @output varchar(max)
select @output = COALESCE(@output + ',','') + name
from tbl_test
where emplyeeid = @userID

return @output
END

GO

SELECT dbo.GetAliasesByID(emplyeeid)
FROM tbl_test
GROUP BY emplyeeid

GO


refer this link
http://stackoverflow.com/questions/122942/how-to-return-multiple-values-in-one-column-t-sql


Regards, Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend