Sunday, February 23, 2014

Issue converting the following query to text.

This is an example, As I said it is not a good approach



set nocount on
declare @tab table(id int,txt varchar(100));
declare @txt varchar(1000);
declare @count int;
insert into @tab
values(1,'Text 1'),(2,'Text 2'),(4,'Text 4');


select *,RN=ROW_NUMBER()OVER(ORDER BY (SELECT NULL)) into #temp from @tab
select @count=@@ROWCOUNT;

while @count>0
begin
select @txt =right(replicate(' ',50)+convert(varchar(50),ID),50) +
right(replicate(' ',50)+convert(varchar(50),txt),50)
from #temp where RN=@count
set @count=@count-1
print @txt
end

drop Table #temp





Satheesh

My Blog | How to ask questions in technical forum



No comments:

Post a Comment