Varshini
asked on
How to insert thousands of records in sql table ?
i have the following table with following columns.
how to insert transid 200001 to 900004
in a single inert command, other columns values are same.
Companyid TransId Date
1 200001 21-Mar-2011
1 200002 21-Mar-2011
1 200003 21-Mar-2011
1 200004 21-Mar-2011
upto
1 900004 21-Mar-2011
how to insert transid 200001 to 900004
in a single inert command, other columns values are same.
Companyid TransId Date
1 200001 21-Mar-2011
1 200002 21-Mar-2011
1 200003 21-Mar-2011
1 200004 21-Mar-2011
upto
1 900004 21-Mar-2011
You can use a while loop
DECLARE @i INT
DECLARE @rows_to_insert INT
SET @i = 200001
SET @rows_to_insert = 900005
WHILE @i < @rows_to_insert
BEGIN
INSERT INTO TABLE (Companyid,TransId,Date)
SELECT 1,@i,'2011-03-21'
SET @i = @i + 1
END
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
User Bulk insert command. Details: http://msdn.microsoft.com/en-us/library/ms188365.aspx
Why would you do that ?
> how to insert transid 200001 to 900004
> in a single inert command, other columns values are same.
I would write a UDF ( User defined function ) which returns me for every TransID between 200001 to 900004 the company ID 1 and the date 21-Mar-2011
> how to insert transid 200001 to 900004
> in a single inert command, other columns values are same.
I would write a UDF ( User defined function ) which returns me for every TransID between 200001 to 900004 the company ID 1 and the date 21-Mar-2011
Open in new window