Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

if statement within sql stored procedures

Posted on 2011-03-24
2
Medium Priority
?
339 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 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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Loops Section Overview

972 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