Solved

if statement within sql stored procedures

Posted on 2011-03-24
2
327 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 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

     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 …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

738 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