SQL Server : Triggers for Insert -


create table tab(id int identity,task_id int,task_descp varchar(10),task_code varchar(10))  insert tab values(7,'bus','b') insert tab values(3,'car','c')  create table tab_detail(  task_descp varchar(10),task_code varchar(10),color varchar(10))  create trigger tab_trigger on tab insert   declare @task_descp varchar(10)   declare @task_code varchar(10)   declare @task_id int   set @task_descp=i.task_descp inserted   set @task_code=i.task_code inserted    set @task_id=i.task_id inserted   if(@task_id=7)     insert tab_detail values(@task_descp,@task_code,'blue')   if(@task_id=3)     insert tab_detail values(@task_descp,@task_code,'green') go 

i want create trigger table tab if insert record based on task_id column record has inserted table tab_detail.

when executing error:

incorrect syntax near keyword 'from'

instead of:

set @task_descp=i.task_descp inserted 

try this:

select @task_descp=i.task_descp inserted 

or this:

create trigger tab_trigger on tab insert         insert tab_detail        select task_descp, task_code, case @task_id when 7 'blue' else 'green' end        inserted         taskid in (7,3)  go 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -