Here i will explain how to get column data into one row.
CREATE TABLE [dbo].[EMP_MAST](
[EMP_CODE] [varchar](10) NULL,
[NAME] [varchar](10) NULL)
INSERT INTO EMP_MAST (EMP_CODE,NAME) VALUES('NJS','Nikhil')
INSERT INTO EMP_MAST (EMP_CODE,NAME) VALUES('BNS','ABC')
after that run this query.
Declare @Str VArchar(Max)
SELECT @Str =Coalesce(@Str +','+ EMP_CODE,EMP_CODE)FROM [dbo].[EMP_MAST]
select @Str
OUTPUT: NJS,BNS
Comments
Post a Comment