TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Get Column Value into Comma Sepreted Using Coalesce() in SQL Server
Nikhil Sangani
Jun 30
2016
Code
1
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
First of all create table and insert record in it.
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
SQL Server
Get Column Value