Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Problem while inserting using default

Author  Topic 

swathigardas
Posting Yak Master

149 Posts

Posted - 2008-09-04 : 04:53:34
Hi, I have two tables one , two.When i'm running the below insert query

create table one (id int default 0, name varchar(10))

create table two (id,name varchar(10))

insert into two values ('hema',2)

insert into one select default,name from two where id=2

The following Error is Shown-

Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'default'.


Please help me out on this

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-04 : 05:26:04
No need of using default there. just use below

insert into one (name)
select name from two where id=2
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-09-04 : 05:33:37
insert into one(name) select name from two where id=2

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-09-04 : 05:34:14
Too slow

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

swathigardas
Posting Yak Master

149 Posts

Posted - 2008-09-04 : 08:14:11
Thanks visakh for the solution
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-09-04 : 08:44:08
quote:
Originally posted by swathigardas

Thanks visakh for the solution


Note that if you want to have default value for a column, exclude it from INSERT statement

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -