SQL SERVER COMMA SEPERATED VALUE IN COLUMN QUERY

We have

SELECT * FROM  STATE

SELECT * FROM CITY

Now to Combine Cityname With it’s StateName

Use Follow Query :

SELECT STATENAME,

SUBSTRING ( (SELECT ‘,’ + CITYNAME   FROM CITY WHERE CITY.STATEID = STATE.STATEID  FOR XML PATH(”)) ,2,1000)

AS CITYNANE

FROM STATE

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s