By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,362 Members | 1,337 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,362 IT Pros & Developers. It's quick & easy.

if then else in stored procedure

P: 58
There is a piece of code from stored procedure.

Expand|Select|Wrap|Line Numbers
  1. BEGIN
  2.  
  3. SET NOCOUNT ON;
  4.     SELECT 
  5.       pi.*
  6. FROM rates pi
  7. WHERE
  8. (pi.pid = @pid or @pid is NULL)     
  9. AND
  10. (pi.scode = @scode or @scode is NULL)
  11.  
  12. 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
Apr 28 '08 #1
Share this Question
Share on Google+
1 Reply


ck9663
Expert 2.5K+
P: 2,878
There is a piece of code from stored procedure.

Expand|Select|Wrap|Line Numbers
  1. BEGIN
  2.  
  3. SET NOCOUNT ON;
  4.     SELECT 
  5.       pi.*
  6. FROM rates pi
  7. WHERE
  8. (pi.pid = @pid or @pid is NULL)     
  9. AND
  10. (pi.scode = @scode or @scode is NULL)
  11.  
  12. 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
Apr 28 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.