Link to home
Start Free TrialLog in
Avatar of Kyle Witter
Kyle WitterFlag for United States of America

asked on

Add multiple rows of data in single SQL statement?

I have a table (User_Values) where I need to create 613 rows of data into columns "User_ValueKey" (primary key) and User_Values (int).  The values are sequential, from 333 to 948.  The data would look like this in the table itself

User_ValueKey      User_Value
333                          333
334                          334
335                          335

And so forth.

Is there a quick way to do this?  I have SQL Server 2008 R2 Express, if that helps.

Thank you!
ASKER CERTIFIED SOLUTION
Avatar of Chris Luttrell
Chris Luttrell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
declare @sx int = 333;
declare @ex int = 948;

with n as (
 select row_number() over (order by object_id) rn from sys.all_objects
 )
select rn+@sx User_ValueKey, rn+@sx User_Value
  from n
 where rn < (@ex-@sx)

Open in new window

Avatar of Kyle Witter

ASKER

Thank you Chris, this did exactly what I needed.  Will definitely save this one for next time.