Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

if statement within sql stored procedures

Posted on 2011-03-24
2
Medium Priority
?
337 Views
Last Modified: 2012-05-11
have attached a quick sql script (albeit not logically correct) -- but hopefully gets the function I am trying to achieve via the stored procedure directly.

how would I script this up correctly please?
USE [db_name]

SELECT [myIndex_ID], [Label]

FROM [myTable]

WHERE ([ActiveMemberStatus] = @ActiveMemberStatus) AND
	if ([Session_ID] = @Session_ID)
		([DistributorType_ID] <> @DistributorType_ID)
	else ([DistributorType_ID] = @DistributorType_ID)
    
ORDER BY [Label]

Open in new window

0
Comment
Question by:amillyard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 35205734
this shall do:
USE [db_name]

SELECT [myIndex_ID], [Label]
FROM [myTable]
WHERE [ActiveMemberStatus] = @ActiveMemberStatus
  AND ( ([Session_ID] = @Session_ID AND [DistributorType_ID] <> @DistributorType_ID)
     OR ([Session_ID] <> @Session_ID AND [DistributorType_ID] = @DistributorType_ID)
      )    
ORDER BY [Label]

Open in new window

0
 

Author Closing Comment

by:amillyard
ID: 35208153
thank you.
0

Featured Post

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question