Solved

if statement within sql stored procedures

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

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now