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)
 i want to select nul and not null values.

Author  Topic 

Sarakumar
Posting Yak Master

108 Posts

Posted - 2006-05-02 : 00:02:35
Hai i have requirment...in emp table for some employee there willnt be any value for the salary column.
In my report i have three input criteria. one is select all the value from tbl where salary > somevalue.
2. where salary < somevalue.
3. Salary 'NA' in this condition
i want to display all the records from the table.
i want to use case statment to solve this..
For 'NA' i need to select all the records. means condition shd be like this.
where salary is not null and salary is null..
how can i do this

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-05-02 : 00:07:56
[code]
select *
from employee
where (@criteria = 1 and salary > @somevalue)
or (@criteria = 2 and salary < @somevalue)
or (@somevalue is null) -- criteria = 3 everything
[/code]


KH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-05-02 : 01:33:54
Also learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp


Madhivanan

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

Sarakumar
Posting Yak Master

108 Posts

Posted - 2006-05-02 : 02:50:06
Thanks a lot for ur Kind Suggestion.
quote:
Originally posted by madhivanan

Also learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp


Madhivanan

Failing to plan is Planning to fail

Go to Top of Page

Sarakumar
Posting Yak Master

108 Posts

Posted - 2006-05-02 : 03:39:29
Hai Related to this, i have one more question
in the Case statement is it possible to use two condition..
means,
case @name when 'R' then 'Rahima'
when 'Z' then 'Zahir' or 'Zen' end something like this


quote:
Originally posted by khtan


select *
from employee
where (@criteria = 1 and salary > @somevalue)
or (@criteria = 2 and salary < @somevalue)
or (@somevalue is null) -- criteria = 3 everything



KH



Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-05-02 : 03:45:00
yes you can use mutiple Conditions within single case..

Case statement is similar to Swtich in programming languages like C++..

for more details on Case look in SQL Server Book online

If Debugging is the process of removing Bugs then i Guess programming should be process of Adding them.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-05-02 : 04:31:31
>>when 'Z' then 'Zahir' or 'Zen' end

Thats not possible
You can use
when 'Z' then 'Zahir or Zen' end

Madhivanan

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

- Advertisement -