Create Table tblApplication (ID int, ApplicationName Varchar(50)) GO
Insert into tblApplication values (1, 'Microsoft')
Insert into tblApplication values (2, 'Apple')
Insert into tblApplication values (1, 'Aditi')
Insert into tblApplication values (1, 'CTS')
Insert into tblApplication values (2, 'Infosys')
Insert into tblApplication values (1, 'Wipro')
Insert into tblApplication values (3, 'Birlasoft')
GO
CREATE FUNCTION dbo.GetApplicationNames
( @AppID INT )
RETURNS VARCHAR(MAX)
AS
BEGIN
DECLARE @ApplicationNames VARCHAR(MAX)
SELECT @ApplicationNames = COALESCE(@ApplicationNames + ', ', '') + ApplicationName
FROM tblApplication
WHERE ID = @AppID
RETURN @ApplicationNames
END
GO
SELECT dbo.GetApplicationNames(1)
GO
No comments:
Post a Comment