Friday, June 12, 2009

procedure in mysql

CREATE PROCEDURE `rtest`.`inpair` (in id int,in lev int)

BEGINDECLARE r int;

DECLARE l int;

select rman into r from tblmancount where regId=id and level=lev and month = month(curdate()) and year =year(curdate());

select lman into l from tblmancount where regId=id and level=lev and month = month(curdate()) and year =year(curdate());

if r

insert into tblpair values(id,lev,r,month(curdate),year(curdate));

elsei

insert into tblpair values(id,lev,l,month(curdate),year(curdate));

end if;

END

Thursday, June 11, 2009

Trigger

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER trigger [tgcom] ON [dbo].[tblTabInfo] after insert
as
declare @foid as varchar(50)
declare @com as decimal(20,2)
declare @qu varchar(10)
select @com=(select focash from tblTableInfo where tableID =(select distinct(tableID) from tblTabInfo where fo_id='0353F1'))
select @qu=(select q_no from tblquarter where getdate() between start_date and end_date )
select @foid= fo_id from inserted
insert into tblcommision_details values (@foid,getdate(),@com,@qu)
update tblcommision set amount=convert(decimal(20,2),amount)+ @com where emp_code=@foid and q_id=@qu
begin
exec focommison @foid, @com
end

Procedure

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER procedure [dbo].[focommison](@foid varchar(50),@amt decimal(20,2))
as begin
declare @id varchar(50)
declare @qu varchar(10)
select @id = (select fo_id from tblfcm where emp_code in(select emp_code from tblFO where fo_id=@foid))
select @qu=(select q_no from tblquarter where getdate() between start_date and end_date )
declare @com decimal(20,2)
select @com=@amt*20/100
if @id is not null
begin
print @id
insert into tblcommision_details values (@id,getdate(),@com,@qu)
update tblcommision set amount=convert(decimal(20,2),amount)+ @com where emp_code=@id and q_id=@qu
exec focommison @id,@com
end
end