Click here to Skip to main content
15,890,391 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
SQL
create table tbl_cyl_gas_master
(
serial_no int,
gas_name varchar(50),
tran_stat varchar(50))

SQL
alter procedure gas
(
@action varchar(20),
@serial_no int,
@gas_name varchar(50),
@tran_stat varchar(50)
)
as
begin
      
       select @tran_stat =(CASE WHEN @action='ADD' then 'FR'
                                                         when @action='Update' then 'FR'
                                                         when @action='Authorise' then 'AU'
                                                         else 'DE'
                                                end )
       --declare @trannew varchar(10),
      
if @action='Add'
       begin
       insert into tbl_Cyl_gas_master values (@gas_name,@tran_stat)
       end
else if @action='Update'
       begin
             
              if @tran_stat == 'FR' && @serial_no==@serial_no
             
                     update tbl_Cyl_gas_master set gas_name=@gas_name where serial_no=@serial_no
             
              else
      
                     RAISERROR ('Transaction not is fresh',16,1);
             
       end
else if @action='Authorise'
       begin
              --select @tran_stat from tbl_cyl_gas_master where serial_no=@serial_no
              if @tran_stat = 'FR'
             
                     update tbl_Cyl_gas_master set tran_stat=@tran_stat where serial_no=@serial_no
             
             
              else
                    
                     RAISERROR ('Transaction already Authorised',16,1)
             
                          
       end
else
       delete gas_name from tbl_Cyl_gas_master where serial_no=@serial_no
 
end
Posted
Updated 1-Apr-14 19:41pm
v4
Comments
Schatak 1-Apr-14 13:23pm    
what error you are getting?

Little modifications in your code:

Try this
CREATE procedure gas
(
@action varchar(20),
@serial_no int,
@gas_name varchar(50),
@tran_stat varchar(50)
)
as
begin
select @tran_stat =(CASE WHEN @action='ADD' then 'FR' when @action='Update' then 'FR' when @action='Authorise' then 'AU'
else 'DE' end )
--declare @trannew varchar(10),

if @action='Add'
begin
	insert into tbl_Cyl_gas_master(gas_name,tran_stat) values (@gas_name,@tran_stat)
end
else if @action='Update'
begin
	if ((@tran_stat = 'FR') AND (@serial_no=@serial_no))
		update tbl_Cyl_gas_master set gas_name=@gas_name where serial_no=@serial_no
	else
		RAISERROR ('Transaction not is fresh',16,1);
	end
else if @action='Authorise'
	begin
	if @tran_stat = 'FR'
		update tbl_Cyl_gas_master set tran_stat=@tran_stat where serial_no=@serial_no
	else
		RAISERROR ('Transaction already Authorised',16,1)
	end
else
	delete gas_name from tbl_Cyl_gas_master where serial_no=@serial_no
end
GO
 
Share this answer
 
Comments
vanarajranjit 1-Apr-14 23:00pm    
Pls check the above reply for solutions 1
Schatak 2-Apr-14 2:05am    
when you are passing 'Authorise' in your Stored Procedure and in a case statement you are saying if when @action='Authorise' then 'AU'
so then next condition "else if @action='Authorise'" is not matching that's why its always saying 'Transaction already Authorised'
vanarajranjit 2-Apr-14 2:19am    
When authorise the serialno it is in fresh status only but it is not authorising it goes to else part transaction already authorised and when transaction is authorised status it should not update but here it is updating. Pls check and revert back.
vanarajranjit 2-Apr-14 2:21am    
When authorise the serialno it is in fresh status only but it is not authorising it goes to else part transaction already authorised and when transaction is authorised status it should not update but here it is updating. Pls check and revert back.add what are the conditions and controls,features in your mind pls add
vanarajranjit 2-Apr-14 2:23am    
I am fresher to sql I am not having much idea now you understand what I written the code so pls make all changesin that code and give to me
Hi,

Replace this line:
SQL
if @tran_stat == 'FR' && @serial_no==@serial_no

with this:
SQL
if (@tran_stat = 'FR' and @serial_no = @serial_no)

and this line:
SQL
insert into tbl_Cyl_gas_master values (@gas_name,@tran_stat)

with this:
SQL
insert into tbl_Cyl_gas_master (gas_name, tran_stat) values (@gas_name, @tran_stat)
 
Share this answer
 
v3
Comments
vanarajranjit 1-Apr-14 22:51pm    
When authorise the serialno it is in fresh status only but it is not authorising it goes to else part transaction already authorised and when transaction is authorised status it should not update but here it is updating. Pls check and revert back.
Andrius Leonavicius 2-Apr-14 2:11am    
Revert back? What kind of RDBMS are you using? As I know, RAISERROR statement should indicate that you're using a SQL Server. So I was checking for syntax errors at first.

Speaking about the code, I don't know why you're using both if @action and if @tran_stat. It seems like unnecessary complexity... I don't know all details, but try to change this line:
--select @tran_stat from tbl_cyl_gas_master where serial_no=@serial_no
if @tran_stat = 'FR'
with this:
if @tran_stat = 'AU'

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900