Monday, February 13, 2012

auto new line in same table

Hi

I have Table Like this In SQL server

Code Name 1001 Bank 1002 Cash


I need a TRIGGER
FOR INSERT, UPDATE, DELETE

that ADD a new Row's in the same table like this:

Code Name 8001 Bank 9001 Bank 8002 Cash 8002 Cash


In other mean for any row add to table by user that code start with 1xxx the trigger must inset to other row to that table whit code 8xxx & 9xxx.

with the same name.

thanks for your help.You could use an INSTEAD OF TRIGGER to do this. Code below should give you an idea of how to do this.

create trigger InsNewRows on tbl instead of insert
as
begin
insert into tbl (Code, Name)
select i.Code, i.Name from inserted as i
union all
select i.Code + n.Code, i.Name
from inserted as i
cross join (select 8000 union all select 9000) as n(Code)
where i.Code between 1000 and 1999
end|||Probably would want to use

where i.Code >= 1000 and cmpid <= 1999

No comments:

Post a Comment