if then else in stored procedure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Garima12
    New Member
    • Mar 2007
    • 58

    if then else in stored procedure

    There is a piece of code from stored procedure.

    Code:
    BEGIN
    
    SET NOCOUNT ON;
    	SELECT 
    	  pi.*
    FROM rates pi
    WHERE
    (pi.pid = @pid or @pid is NULL) 	
    AND
    (pi.scode = @scode or @scode is NULL)
    
    END
    I want to put a condition in this:
    If scode = 'p' then
    where condition must be like this:
    WHERE
    (pi.pid = @pid or @pid is NULL)
    AND
    ((pi.scode = @scode and pi.scode ='p' ) or @scode is NULL)

    Please tell me how to modify the code?
    thks
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Originally posted by Garima12
    There is a piece of code from stored procedure.

    Code:
    BEGIN
    
    SET NOCOUNT ON;
    	SELECT 
    	  pi.*
    FROM rates pi
    WHERE
    (pi.pid = @pid or @pid is NULL) 	
    AND
    (pi.scode = @scode or @scode is NULL)
    
    END
    I want to put a condition in this:
    If scode = 'p' then
    where condition must be like this:
    WHERE
    (pi.pid = @pid or @pid is NULL)
    AND
    ((pi.scode = @scode and pi.scode ='p' ) or @scode is NULL)

    Please tell me how to modify the code?
    thks
    On this part:

    If scode = 'p'

    Is scode a variable or a column?

    -- CK

    Comment

    Working...