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
 General SQL Server Forums
 New to SQL Server Programming
 Looping through to create a test data

Author  Topic 

sqlservernovice
Starting Member

9 Posts

Posted - 2012-12-13 : 16:26:34
Hi,

i have data in the format of a date and the key for each day and for each key i have to create 10 values as part of creating test data.

how can i do it using sql server
date key
2011-01-01 221
2011-01-01 23232
2011-01-01 234234
2011-01-01 2343
2011-01-01 987
2011-01-01 6602
2011-01-01 787879
2011-01-01 8605578


the output would look like

2011-01-01 221 1 0


2011-01-01 221 2 0

2011-01-01 221 3 0

... so on 10 values


2011-01-01 23232 1 0

2011-01-01 23232 2 0...

so on.

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2012-12-13 : 19:48:03

Here is what i understood

Select t.date,P.a,0 from Table t
OUTER APPLY
( Select 1 as a
union all
Select 2
union all
Select 3
)P
Go to Top of Page

sqlservernovice
Starting Member

9 Posts

Posted - 2012-12-14 : 10:05:38
Thanks, this works for me.
Go to Top of Page
   

- Advertisement -