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
 Please advice... :(

Author  Topic 

John_Mc_2009
Starting Member

7 Posts

Posted - 2008-11-25 : 11:34:13
Hi All,

Can somebody advice how to have condition on selecting the columns for the INSERT statement. I tried with CASE statement like below, but got error "Incorrect syntax near the keyword 'CASE'."
empagerange20,empagerange40,empagerange60 are columns in employee table.


insert into employee
(id, empname,
CASE when age =20 then empagerange20
CASE when age =40 then empagerange40
CASE when age =60 then empagerange60
end,
datecreated)
select tempid, age,getdate() from logemployee;

Please advice...why it is giving error OR any other suggestion...


visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-25 : 11:41:38
you cant use case in insert list. what you want is this

insert into employee
(id, empname,empagerange20,empagerange40,empagerange60,datecreated)
select tempid,
some value here for empname,
CASE when age =20 then age end,
CASE when age =40 then age end,
CASE when age =60 then age end,
getdate() from logemployee;
Go to Top of Page
   

- Advertisement -