Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 conditional t-sql select phrase construction

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-09-20 : 07:10:09
CLAUDIO writes "How can I write something similar to the below reported ...working


SELECT
*
FROM
XTBL
WHERE
XTBL.A = 'A'
IF SOMETHING HAPPENS THEN
AND XTBL.B = 'B'
END"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-20 : 07:21:21
[code]
If exists(SELECT * FROM XTBL WHERE XTBL.A = 'A')
SELECT * FROM XTBL WHERE XTBL.A = 'A' AND XTBL.B = 'B'
[/code]

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2005-09-20 : 09:56:16
Something like this maybe?

DECLARE @Foo varchar(10) = NULL

SELECT
<List>
FROM
XTBL
WHERE
XTBL.A = 'A'
AND
XTBL.B = CASE @Foo WHEN NULL THEN XTLB.B ELSE @Foo END


Help us help YOU!
Read this blog entry for more details: http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

*need more coffee*
SELECT * FROM Users WHERE CLUE > 0
(0 row(s) affected)
Go to Top of Page
   

- Advertisement -