Saturday, 11 June 2011

woking with procedure simple Example


stored procedure-simple example to understand the functionality procedure this example will give the calculation of  items when we put it id and item name 

create proc pp  //'Aoo3','biscuit',''
(
@id char(5),
@prname varchar(12),
@price float=null
)
as
begin

declare @comm as int,@grossamount as float, @tax as numeric(5,2),@productprname as varchar(12),@productprice as float
declare @totaltax as int

set @productprname=(select productname from prduct where product_id=@id)
set @productprice=(select productprice from prduct where product_id=@id)
if(@prname='colgate')
begin
set @comm=2
set @totaltax=5
set @grossamount=@productprice-(@productprice*@comm/100)+@totaltax
select @grossamount
end
else
    if(@prname='soap')
     begin
     set @comm=1
     set @totaltax=2
 set  @grossamount=@productprice-(@productprice*@comm/100)+@totaltax
     select @grossamount as Totalcost
     end
else
     if(@prname='biscuit')
     begin
     set @comm=3
     set @totaltax=4
 set  @grossamount=@productprice-(@productprice*@comm/100)+@totaltax
    select @grossamount as Totalcost
     end
else
    if(@prname='oil')
     begin
     set @comm=7
     set @totaltax=2
 set  @grossamount=@productprice-(@productprice*@comm/100)+@totaltax
    select @grossamount as Totalcost
     end
else
    if(@prname='tobaco')
     begin
     set @comm=5
     set @totaltax=5
 set  @grossamount=@productprice-(@productprice*@comm/100)+@totaltax
    select @grossamount as Totalcost
     end
end


continue....more

No comments:

Post a Comment