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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if...in the where clause

Status
Not open for further replies.

sexydog

Programmer
Jul 9, 2002
176
0
0
GB
where
if @choice = 'province' then
@province in (select province_name
from p_provinces
where @province..........


how can i do this
 
Since you are passing in parameters then maybe it is a stored procedure that you are running?

If so you could construct your sql statement in code based on the inputs

declare @sqlString as varchar(255)
...
select @sqlString = @sqlString + @sqlwhere
...
EXEC master.dbo.sp_SQLEXEC @sqlString
 
Try the following construction:

WHERE
Case
WHEN @Choice = 'province' THEN (SELECT 1 FROM p_provinces where @province ...)
ELSE 0
END is Not Null
 
How about this?

If @choice = 'province'
Begin
If Exists
(Select * From p_provinces
Where Province=@province)
Begin
<Province found code>
End
Else
Begin
<Province not found code>
End
End
Else
Begin
<@choice <> 'Province' code>
End
Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains &quot;Suggestions for Getting Quick and Appropriate Answers&quot; to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top