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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Looping through to create a test data
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sqlservernovice
Starting Member

9 Posts

Posted - 12/13/2012 :  16:26:34  Show Profile  Reply with Quote
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.

Edited by - sqlservernovice on 12/13/2012 16:48:54

sodeep
Flowing Fount of Yak Knowledge

USA
7174 Posts

Posted - 12/13/2012 :  19:48:03  Show Profile  Reply with Quote

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 - 12/14/2012 :  10:05:38  Show Profile  Reply with Quote
Thanks, this works for me.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000