Solved

if statement within sql stored procedures

Posted on 2011-03-24
2
318 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
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

820 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