Sql Inserting Multiple rows into a Table

Written by kieron on August 6th, 2010

After spending hours trying to work out why the sql bulk insert command refused to work. (it always claimed it could not open the file but the permission sets looked fine) I found Pinalkumar Dave’s blog at http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/ and the example code worked wonderfully for me. So I had to do was to edit the data file, but a few change and replaces are better the inserting the values n times

A quick example

Insert into usage (Forename,Surname,Town)
Select ‘Fred’,’Smith’,’Manchester’
union all
Select ‘Bob’,’Jones’,’Wigan’
union all
Select ‘Anna,’Bell’,Stockport’’
Go

So thank you again Pinal Dave

 

Leave a Comment