I want to consolidate results of multiple queries in 1 column or variable.
I have this Query :-
select Id from EmployeeDetail where Code = 'ABC1'
select Id from EmployeeDetail where Code = 'ABC2'
... So On till ABC200
declare @num int
declare @num1 VARCHAR(MAX)
set @num = 1
declare @results table ( val int )
while (@num < 84)
insert into @results ( val ) values ( @num )
set @num = @num + 1
set @num1 += '5000'
If the EmployeeDetail codes your are fetching all match some pattern, then you can achieve what you want using the simple query below:
declare @AllIDs varchar(max) set @AllIDs = '' select @AllIDs = (@AllIDs + cast(ID as varchar(10)) + ',') from EmployeeDetail WHERE Code like 'ABC%'
After you run it, variable @AllIDs will contain all the IDs separated with ',' .