RSS

Insert multiple records to a table using single query in sqlserver

13 Aug

create table tblEmp (eid int, ename varchar(20), estatus bit)

sqlserver2005

insert into tblEmp select 1,’emp1′,’True’

union all select 2,’emp2′,’True’

union all select 3,’emp3′,’True’

sqlserver2008

insert into tblEmp values (1,’emp1′,’True’),(2,’emp2′,’True’),(3,’emp3′,’True’)

 

If table not exist in database then:

select * into tblEmp from (select 1 eid,’emp1′ ename,’True’ estatus) tbltemp

About these ads
 
Leave a comment

Posted by on August 13, 2012 in .NET, SQL SERVER

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: