1

can we make multiple rows as comma seperated in SQL Query?

query should return something like:

1, "john,mike,petra"
2, "bob,carl,sandra,peter,
etc
Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
Febin J S
  • 1,358
  • 3
  • 26
  • 53

2 Answers2

1

This can easily be acomplished via Management Studio enter image description here

Mick Walker
  • 3,862
  • 6
  • 47
  • 72
1

Do you want the all the columns to be comma separated and concatenated as a single string for each row? If yes, you can use this code.

select Name+','+Phone_NO+','+Address from <table_name>

Result will be looked like the following lines:

  1. Bob,6589235,Anderson Street

  2. Jake,8547868,Jefferson Street

If your column is not varchar type then you have to cast the columns.

Luniam
  • 463
  • 7
  • 21