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.
Author |
Topic |
baska123
Yak Posting Veteran
64 Posts |
Posted - 2006-09-08 : 12:41:14
|
I have this where clause that depending on the situation I want to use different 'and' statement. How can I do it?where a.AssignmentTimeActualWork IS not NULL and a.AssignmentTimeActualWork <>0 and AssignmentTimeStart >= @StartDate and AssignmentTimeStart <= @EndDatethis is my choice. I want to use this one and b.wres_id_mgr = @ResourceID or I want to use and b.wres_id In (Select ID From fnSplitter(@IDs)) |
|
X002548
Not Just a Number
15586 Posts |
|
Kristen
Test
22859 Posts |
Posted - 2006-09-08 : 13:02:45
|
Most commonly I see thie done passing NULL for "don't care" parameters:and (@ResourceID IS NULL OR b.wres_id_mgr = @ResourceID)and (@IDs IS NULL OR b.wres_id In (Select ID From fnSplitter(@IDs))) Kristen |
 |
|
baska123
Yak Posting Veteran
64 Posts |
Posted - 2006-09-08 : 13:17:12
|
My condition should beIf @ResourceID = 'All Resources then' and b.wres_id In (Select ID From fnSplitter(@IDs))else and b.wres_id_mgr = @ResourceID |
 |
|
X002548
Not Just a Number
15586 Posts |
|
baska123
Yak Posting Veteran
64 Posts |
Posted - 2006-09-08 : 15:32:09
|
Is it possible to have if esle statements in the middle of sql. For example:Select name, l_name from names where age = 25 and gender = F if @ResourceID = All Resources begin and b.wres_id_mgr = @ResourceID endelse and b.wres_id In (Select ID From fnSplitter(@IDs) |
 |
|
X002548
Not Just a Number
15586 Posts |
|
Kristen
Test
22859 Posts |
Posted - 2006-09-09 : 03:59:41
|
No, as Brett said, but its can easily be expressed as just another AND with a nested OR ...Kristen |
 |
|
baska123
Yak Posting Veteran
64 Posts |
Posted - 2006-09-11 : 15:58:09
|
What do you mean Kristen? |
 |
|
Kristen
Test
22859 Posts |
Posted - 2006-09-12 : 02:34:57
|
"What do you mean Kristen?"Wellwhereage = 25 and gender = Fif @ResourceID = All Resourcesbeginand b.wres_id_mgr = @ResourceID endelseand b.wres_id In (Select ID From fnSplitter(@IDs)is the same as being expressed as:whereage = 25 and gender = FAND ( ( @ResourceID = All Resources and b.wres_id_mgr = @ResourceID ) OR b.wres_id In (Select ID From fnSplitter(@IDs)) isn't it?Kristen |
 |
|
|
|
|