RE: Conditional Join?
From: Hal Heinrich (HalHeinrich_at_discussions.microsoft.com)
Date: 01/10/05
- Next message: Tibor Karaszi: "Re: The number of the week."
- Previous message: lindawie: "Re: Update Performance"
- In reply to: Brian: "Conditional Join?"
- Next in thread: Hugo Kornelis: "Re: Conditional Join?"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 10 Jan 2005 14:31:05 -0800
The following may help:
WHERE c_language_skills = CASE WHEN @language_id = 'NA' THEN
c_language_skills ELSE @language_id END
Note that this will always exclude records where c_language_skills is null.
The following includes those:
WHERE COALESE(c_language_skills, 'NULL') = CASE WHEN @language_id = 'NA'
THEN COALESE(c_language_skills, 'NULL') ELSE @language_id END
"Brian" wrote:
> I currently have a stored proc that is dynamic. I build it up based in a
> variety of variables passed in. I would like to move away from this if
> possible.
>
> I have one sticking point, I have a series of statements like this
>
> if @language_id <> 'NA'
> BEGIN
> set @joins = @joins+' JOIN c_language_skills ls ON c.candidate_id =
> ls.candidate_id'
> set @where = @where+' AND ls.language_id IN ('+@language_id+')'
> END
>
> Is it possible to use a CASE statement or maybe COALESCE ?
>
> The join is optional because the user didn't need to query, in this case, on
> the language skills. If I used Coalesce and had Null would it query all
> the rows or ignore it?
>
> Hope that makes sense.
>
> Thanks
>
>
>
- Next message: Tibor Karaszi: "Re: The number of the week."
- Previous message: lindawie: "Re: Update Performance"
- In reply to: Brian: "Conditional Join?"
- Next in thread: Hugo Kornelis: "Re: Conditional Join?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|