Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
if exists(select * from K_RT_AmountReceived where trno=@trno)
   if exists(select *from K_RT_AmountReceived where trno = @trno and recamount = @recamount)
    begin
    select '2' as status
    end
    else
    begin
    insert into K_RT_AmountReceived(partyname,date,recamount,chequeno,trno,updatedby,updatedon)values(@partyname,@date,@recamount,@chequeno,@trno,@username,getdate())
    select '1' as status
    end


i want to exists multiple if statements..above code shows an error
Posted
Updated 7-Feb-14 23:30pm
v2
Comments
[no name] 8-Feb-14 5:22am    
What is the problem..?
Siva Hyderabad 8-Feb-14 5:26am    
i want to exists multiple if statements..above code shows an error
[no name] 8-Feb-14 5:27am    
Please improve the question and provide proper information with the error you are getting..else it's difficult to identify what you are trying to do..

You don't need to: your "nested" if contains the clause in the outer if as well!
So just dump the outer condition...
 
Share this answer
 
try this

SQL
if exists (select * from K_RT_AmountReceived where trno=@trno)
begin
       if exists(select *from K_RT_AmountReceived where trno = @trno and recamount = @recamount)
            begin
                select '2' as status
            end
        else
            begin
                insert into K_RT_AmountReceived(partyname,[date],recamount,chequeno,trno,updatedby,updatedon)values(@partyname,@date,@recamount,@chequeno,@trno,@username,getdate())
                select '1' as status
            end
 end
 
Share this answer
 
Comments
Siva Hyderabad 8-Feb-14 6:32am    
hi karthik,i have a doubt?
Siva Hyderabad 8-Feb-14 6:34am    
MessageBox.Show() with Yes or No confirmation dialog box displayed in Windows Forms Application..Now I want to Shows as same as in aspx.cs page..How to write code..Which namespace i added here?
Karthik_Mahalingam 8-Feb-14 22:15pm    
hi siva,
now only i am back to system, yesterday i went to movie and came back late nite...
you can achieve this using modal pop up
SQL
if exists(select * from K_RT_AmountReceived where trno=@trno)
    and exists(select *from K_RT_AmountReceived where trno = @trno and recamount = @recamount)
    begin
    select '2' as status
    end

    else
    begin
    insert into K_RT_AmountReceived(partyname,date,recamount,chequeno,trno,updatedby,updatedon)values(@partyname,@date,@recamount,@chequeno,@trno,@username,getdate())
    select '1' as status
    end
 
Share this answer
 
SQL
if exists(select * from K_RT_AmountReceived where trno=@trno)
begin
   if exists(select *from K_RT_AmountReceived where trno = @trno and recamount = @recamount)
    begin
         select '2' as status
    end
    else
    begin
         insert into K_RT_AmountReceived (partyname,date,recamount,chequeno,trno,updatedby,updatedon)
         values(@partyname,@date,@recamount,@chequeno,@trno,@username,getdate())
    select '1' as status
    end
end
 
Share this answer
 

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