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
 General SQL Server Forums
 New to SQL Server Programming
 insertion problem

Author  Topic 

Tamer
Starting Member

22 Posts

Posted - 2008-08-20 : 06:25:58
Dear Experts,

what is the problem with this statment
**********
insert into employee1(e_no,e_name1)
select employee.e_no,employee.e_name1
when employee.e_no=1 then 1000
when employee.e_no=2 then 2500
else employee.e_no end
from employee
**********
I got this in the message tab
Incorrect syntax near the keyword 'when'.

Thanks in Advance

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-20 : 06:29:40
insert into employee1(e_no,e_name1,othercol)
select employee.e_no,employee.e_name1
case when employee.e_no=1 then 1000
when employee.e_no=2 then 2500
else employee.e_no end
from employee



Madhivanan

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

Tamer
Starting Member

22 Posts

Posted - 2008-08-20 : 06:55:31
According to your statment

I get this message in the message tab

Incorrect syntax near the keyword 'case'

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-20 : 07:02:25
quote:
Originally posted by madhivanan

insert into employee1(e_no,e_name1,othercol)
select employee.e_no,employee.e_name1,
case when employee.e_no=1 then 1000
when employee.e_no=2 then 2500
else employee.e_no end
from employee



Madhivanan

Failing to plan is Planning to fail


missed a comma
Go to Top of Page

Tamer
Starting Member

22 Posts

Posted - 2008-08-20 : 07:07:42
I am so sorry , but I get this in the message tab

The select list for the INSERT statement contains more items than the insert list. The number of SELECT values must match the number of INSERT columns.

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-20 : 07:12:51
quote:
Originally posted by Tamer

I am so sorry , but I get this in the message tab

The select list for the INSERT statement contains more items than the insert list. The number of SELECT values must match the number of INSERT columns.




You should specify the third column
See my query

Madhivanan

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

Tamer
Starting Member

22 Posts

Posted - 2008-08-20 : 08:44:43
Thank you Mr.

but this retrieve the data without changing it according to the criteria in the case...end
it bring the data as it is in the original table

Tamer
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-20 : 09:18:38
quote:
Originally posted by Tamer

Thank you Mr.

but this retrieve the data without changing it according to the criteria in the case...end
it bring the data as it is in the original table

Tamer


why? waht was your e_no value? and what value you got for third column?
Go to Top of Page

Tamer
Starting Member

22 Posts

Posted - 2008-08-20 : 09:26:55
Ok Mr.

The idea is clear now

Thank you very much
Go to Top of Page
   

- Advertisement -