Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selective Inclusion of SQL commands - Coldfusion conversion question 1

Status
Not open for further replies.

ice7899

Programmer
May 14, 2006
59
GB
Hello

I'm converting a coldfusion query to a stored procedure

The Coldfusion query runs something like this:

SELECT Column1
WHERE Column2 = 0

<cfif someVar = 3>
AND Column3=0
</cfif>

How can I achieve the selective inclusion of AND clauses in TSQL ?



 
Code:
SELECT Column1
From   Table
WHERE  Column2 = 0
       And (
           (@SomeVar = 3 And Column3 = 0)
           Or IsNull(@SomeVar, 0) <> 3
           )

Use OR. In this case, if @SomeVar = 2 then IsNull(@SomeVar, 0) <> 3 will return true, so the record will be included whether column3 = 0 or not.

Does this make sense?

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top