I woul like to join table with other table only in case when @.myParam is
null.
Example:
something like that:
...table1 T1
case when @.myParam is null then
INNER JOIN table2 T2 ON T1.zone=T2.zone
else end
.....
Is that possible?
Thnk you,
Simonsimon
Use pubs
SELECT a.au_lname, a.au_fname, a.address,
t.title, t.type
FROM authors a INNER JOIN
titleauthor ta ON ta.au_id = a.au_id INNER JOIN
titles t ON t.title_id = ta.title_id
INNER JOIN publishers p on t.pub_id =
CASE WHEN t.type = 'Business' THEN p.pub_id ELSE null END
INNER JOIN stores s on s.stor_id =
CASE WHEN t.type = 'Popular_comp' THEN t.title_id ELSE null END
"simon" <simon.zupan@.stud-moderna.si> wrote in message
news:OwhFXArOFHA.1476@.TK2MSFTNGP09.phx.gbl...
> I woul like to join table with other table only in case when @.myParam is
> null.
> Example:
> something like that:
> ...table1 T1
> case when @.myParam is null then
> INNER JOIN table2 T2 ON T1.zone=T2.zone
> else end
> .....
> Is that possible?
> Thnk you,
> Simon
>|||Hi Uri,
thank you for your answer.
I have little different example ( also instead of "=" I have like) .
If myParam is not null, my table2 is empty.
So inner join:
table1 T1 INNER JOIN table2 T2 ON T1.zone like
CASE when @.myParam is null then T2.zone else NULL END
will not work correctly.
I tried like this:
table1 T1 INNER JOIN table2 T2 ON 1=
(CASE when @.myParam is not null then 1 else case when T1.zone like
'%'+T2.zone+'%' then 1 else 0 end end )
It works but it's too slow.
Any idea?
Regards,
Simon
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:e3FBGDrOFHA.244@.TK2MSFTNGP12.phx.gbl...
> simon
> Use pubs
> SELECT a.au_lname, a.au_fname, a.address,
> t.title, t.type
> FROM authors a INNER JOIN
> titleauthor ta ON ta.au_id = a.au_id INNER JOIN
> titles t ON t.title_id = ta.title_id
> INNER JOIN publishers p on t.pub_id =
> CASE WHEN t.type = 'Business' THEN p.pub_id ELSE null END
> INNER JOIN stores s on s.stor_id =
> CASE WHEN t.type = 'Popular_comp' THEN t.title_id ELSE null END
>
> "simon" <simon.zupan@.stud-moderna.si> wrote in message
> news:OwhFXArOFHA.1476@.TK2MSFTNGP09.phx.gbl...
>|||Simon
Try this one (untested)
table1 T1 INNER JOIN table2 T2 ON 1=
CASE
WHEN EXISTS (
SELECT * FROM Table2
WHERE T1.zone like '%'+T2.zone+'%')
THEN 1
ELSE 0
END
"simon" <simon.zupan@.stud-moderna.si> wrote in message
news:%23xd$3RrOFHA.2144@.TK2MSFTNGP09.phx.gbl...
> Hi Uri,
> thank you for your answer.
> I have little different example ( also instead of "=" I have like) .
> If myParam is not null, my table2 is empty.
> So inner join:
> table1 T1 INNER JOIN table2 T2 ON T1.zone like
> CASE when @.myParam is null then T2.zone else NULL END
> will not work correctly.
> I tried like this:
> table1 T1 INNER JOIN table2 T2 ON 1=
> (CASE when @.myParam is not null then 1 else case when T1.zone like
> '%'+T2.zone+'%' then 1 else 0 end end )
> It works but it's too slow.
> Any idea?
> Regards,
> Simon
>
> "Uri Dimant" <urid@.iscar.co.il> wrote in message
> news:e3FBGDrOFHA.244@.TK2MSFTNGP12.phx.gbl...
is
>
No comments:
Post a Comment