dbTalk Databases Forums  

INSERTing multiple rows

comp.databases comp.databases


Discuss INSERTing multiple rows in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
metaperl
 
Posts: n/a

Default INSERTing multiple rows - 11-16-2009 , 08:21 AM






How could I (under T-SQL) combine make this INSERT statements simpler:

INSERT INTO ig VALUES ('050016994' , 1999, 14.0)
INSERT INTO ig VALUES ('050016995' , 1999, 14.0)
INSERT INTO ig VALUES ('050016996' , 1999, 14.0)


I dont want to simply have 3 VALUES clauses for one INSERT:

INSERT INTO ig VALUES ('050016994' , 1999, 14.0) VALUES ( ...) VALUES
( ...)

But I want to somehow use a SELECT to "stream" the variable value in:

INSERT INTO ig (column_name, 1999, 14.0) (SELECT column_name FROM
table WHERE column_name BETWEEN '050016994' AND '050016996')

Reply With Quote
  #2  
Old   
Lennart
 
Posts: n/a

Default Re: INSERTing multiple rows - 11-16-2009 , 11:50 AM






On 16 Nov, 15:21, metaperl <metap... (AT) gmail (DOT) com> wrote:
Quote:
How could I (under T-SQL) combine make this INSERT statements simpler:

INSERT INTO ig VALUES ('050016994' , 1999, 14.0)
INSERT INTO ig VALUES ('050016995' , 1999, 14.0)
INSERT INTO ig VALUES ('050016996' , 1999, 14.0)

I dont want to simply have 3 VALUES clauses for one INSERT:

INSERT INTO ig VALUES ('050016994' , 1999, 14.0) VALUES ( ...) VALUES
( ...)

But I want to somehow use a SELECT to "stream" the variable value in:

INSERT INTO ig (column_name, 1999, 14.0) (SELECT column_name FROM
table WHERE column_name BETWEEN '050016994' *AND '050016996')
insert into ....
select column_name, 1999, 14.0 from T where ...

/Lennart

Reply With Quote
  #3  
Old   
--CELKO--
 
Posts: n/a

Default Re: INSERTing multiple rows - 11-18-2009 , 05:29 AM



SQL Server 2008 finally has the table constructor syntax:

INSERT INTO ig
VALUES ('050016994' , 1999, 14.0),
('050016995' , 1999, 14.0),
('050016996' , 1999, 14.0);


Quote:
I dont want to simply have 3 VALUES clauses for one INSERT:
Of course not! Your syntax was illegal.

Quote:
But I want to somehow use a SELECT to "stream" the variable value in:
Unh? SQL is set-oriented; we insert a whole set and not a stream.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.