Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to write a select statement Which repeats

Author  Topic 

mrajakrishnan
Starting Member

3 Posts

Posted - 2009-11-04 : 13:33:44
Hi,

I have a requirment like if i give a count value it should repeat the result that number of time.


eg) If there is a variable @test='Raja'

and if i give count as 5


I need the result like
Raja
Raja
Raja
Raja
Raja

This i can do like

while{i<6)
begin

select @test
i=i+1
end



But without loop is it possible to get the result using simple SQL statment?

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-11-04 : 13:39:13
[code]SELECT 'Raja'
FROM master..spt_values
WHERE type='p'
AND number <= 5[/code]
Go to Top of Page
   

- Advertisement -