By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,915 Members | 1,337 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,915 IT Pros & Developers. It's quick & easy.

NULLIF or CASE - Decode

P: n/a
Hi,

-- SQL Stmt 1
SELECT * FROM Table1
WHERE Field1 = 123
AND Field2 = 234
AND Field3 = 345
AND Field4 = 456
AND Field5 = 567
AND Field6 = 678

-- SQL Stmt 2
IF @@ROWCOUNT = 0
SELECT * FROM Table1
WHERE Field1 = 123
AND Field2 = 234
AND Field3 = 345
AND Field4 = 456
AND Field5 = 567

I want to use a single SQL Stmt instead of 2 SQL Stmts.
I am not looking for "(Field1 = 123 ..... and Field6 = 678) or (
field1 = 123... and field5 = 567)"
I know this can be achieved in Oracle with Decode.
I was looking for a similar solution on SQL Server.
May be possible with NULLIF and or Case.

I am attaching script for creating a table
CREATE TABLE Table1
(
Field1 INT,
Field2 INT,
Field3 INT,
Field4 INT,
Field5 INT,
Field6 INT
)

-- Hareesh
Jul 20 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.