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)
 Is this possible in SQL ... Yes / No

Author  Topic 

nssjari
Starting Member

46 Posts

Posted - 2005-07-06 : 08:57:06
To select few fields from respective table depending on the value of the field and according apply condition of the where clause.
select a, b, c, d, e, f

I mean

if a value of the field d in select clause is not null
then do check for a where clause expression1 and expression2
else do check only for the where clause expression1 only

Also if a value of the field d in select clause is null,
it should not select d, e, f

Is this possible in SQL or PL/SQL if so whats the SQL syntax

Please do reply ASAP
Jari

Jari
Computer Engg

Crito
Starting Member

40 Posts

Posted - 2005-07-06 : 09:05:11
your where clause would look something like:

WHERE
(Field1 = X OR Field1 IS NULL)
AND
(Field2 = X OR Field2 IS NULL)

etc...



----------------------------------
Gun for hire, have horse, will travel.
Go to Top of Page

nssjari
Starting Member

46 Posts

Posted - 2005-07-06 : 09:14:46
I need to apply this logic to the question posted below ...

"select a, b, case when exp then c, d try if u can ... nssjari"

Please have a look at this problem if you can spare a little time ...

Jari
Computer Engg
Go to Top of Page

Crito
Starting Member

40 Posts

Posted - 2005-07-06 : 09:20:53
Looks like you answered your own question: use a case statement in your select clause.



----------------------------------
Gun for hire, have horse, will travel.
Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2005-07-06 : 09:22:27
Your SELECT statement will always return a constant number of columns. You cannot conditionally return a col.umn though you can return Null for that column. If you want to return two versus three columns, put that logic into an IF statement.

HTH

=================================================================
None are more hopelessly enslaved than those who falsely believe they are free. -Johann Wolfgang van Goethe, poet, dramatist, novelist, and philosopher (1749-1832)
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2005-07-06 : 09:33:44
"Is this possible in SQL or PL/SQL if so whats the SQL syntax"
This translates to "I do not wish to learn to do crap for myself: " +

1) Do my homework for me now
OR
2) Do my open book test for me now
OR
3) Do my job for me now

If I am wrong, my apologies. Otherwise, feel free to go pound sand.

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

Crito
Starting Member

40 Posts

Posted - 2005-07-06 : 09:43:53
Methinks Don needs to switch to decaf... LOL

----------------------------------
Gun for hire, have horse, will travel.
Go to Top of Page

nssjari
Starting Member

46 Posts

Posted - 2005-07-06 : 09:44:44
Hey thats cool ...

You are very smart ... is that what you feel ... Hahahaha
I am seriously asking something if you can look into it ...
nobody is forcing anybody here right dear ...

Anyways nice to hear from you ... Thanks a lot
For you philosophical query ...

Your friend Jari

quote:
Originally posted by DonAtWork

"Is this possible in SQL or PL/SQL if so whats the SQL syntax"
This translates to "I do not wish to learn to do crap for myself: " +

1) Do my homework for me now
OR
2) Do my open book test for me now
OR
3) Do my job for me now

If I am wrong, my apologies. Otherwise, feel free to go pound sand.

*need more coffee*
SELECT * FROM Users WHERE CLUE > 0
(0 row(s) affected)



Jari
Computer Engg
Go to Top of Page

nssjari
Starting Member

46 Posts

Posted - 2005-07-06 : 09:49:55
Hey I am sorry if I am troubling you ...
Actually it relates very much to a query already posted ...
So if you look at it ... you would know what i am asking for ...

Anyways love you friend for sparing your presious time for me...
Wish you all the best for your future ...

Your good friend ... Jari

quote:
Originally posted by Crito

Methinks Don needs to switch to decaf... LOL

----------------------------------
Gun for hire, have horse, will travel.



Jari
Computer Engg
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2005-07-06 : 10:17:23
I do drink decaf

The way the questions are worded just sound like that to me is all. No code attempts, no DDL, no nothing.

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

- Advertisement -