insert into table1 (colname) values (value1)
can only insert one record into the table. How to insert multiple records as value1, value2, value3... into a table?
We can of course use the above repeatedly, but if I don't know how many records (which is a variable), and I want to write a code which just take
value1, value2, value3 ...
from the clipboard, to paste as a input. How to insert those multiple records into table without split it. Thanks
What is the source of the data? from another table?
|||If you are taking values from another table then you can insert multiple records.
Any ways i think it internally dosen't make much difference if you use multiple records or single record multiply internall it will fire that many insert statements only.
I find this intresting article guess it will help
http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/
|||
U want place into the same table r other clarity is required
Insert into x select * from x
insert into x select * from y
If u want to copy the data of entire table use * other wise U have to specify column clause
Thank u
Baba
Please remember to click "Mark as Answer" on this post if it helped you.
I hope I'm getting your question right.
Are you looking for something like
insert into table1 ( colname )
select value1 union all
select value2 union all
.
.
.
select valueN
If you can specify your problem in details then we can help you better.
Thank everyone for your input. What I want was taking the contents of multiple records delimited by delimiter from clipboard as a string, then insert into a table. I complished by writing a user function which takes a string, then output a table with multiple records, it works as
insert into table1 (ID)
select values from fn_StringToTable(@.myString, @.delimiter) -- here @.myString='00a1,00a2,00a3,...'; @.delimiter=','
output table1 got the IDs from the clipboard which has'00a1,00a2,00a3,...
Thanks
No comments:
Post a Comment