How to get rows as comma separated values.
select [name] from sys.objects where type='u'
i get this :
DropDownList
SubActivityDetails
Report
Employees
UserMaster
ProjectMaster
i want this :
DropDownList,SubActivityDetails,Report,Employees,UserMaster,ProjectMaster
in a single Query only
And also in this case
select [name],[object_id] from sys.objects where type='u'
I get this:
DropDownList 66099276
SubActivityDetails 197575742
Report 254623950
Employees 270624007
But I want this:
["SubActivityDetails",197575742],
["Report",254623950],
["Employees",270624007]
so that its similar to json.
And there would be lot of data, so performance is a major concern!
which is better
case 1 :
DECLARE @Val VARCHAR(MAX)
begin
select @Val = isnull(@val + ‘,’ + [name],[name])
from sys.objects
where type=’u’
SELECT @Val
end
case 2 :
DECLARE @Val VARCHAR(MAX)
begin
select @Val = COALESCE(@val + ‘,’ + [name],[name])
from sys.objects
where type=’u’
SELECT @Val
end
Have a look at something like this
Ok, so for the second query we can try