I am creating a stored procedure which has multiple joins. Now the problem is I want some joins to be executed for a given condition and some other join for other condition. For example
select c.cid, m.name, f.fname, l.lname
from tblcust c
left join tblmname m on c.id = m.cid
left join tblfname f on f.id = c.id
left join tbllname on l.id = c.id
What I want to do is
declare @val As varchar(10)
select @val = 'left join tblmname m on c.id = m.cid'
select c.cid, m.name, f.fname, l.lname
from tblcust c
left join tblmname m on c.id = m.cid
If condition is true then
+ @val +
left join tbllname on l.id = c.id
How to concatinate user defined variable in select clause?
Thanks in advance,
Govind
select c.cid, m.name, f.fname, l.lname
from tblcust c
left join tblmname m on c.id = m.cid
left join tblfname f on f.id = c.id
left join tbllname on l.id = c.id
What I want to do is
declare @val As varchar(10)
select @val = 'left join tblmname m on c.id = m.cid'
select c.cid, m.name, f.fname, l.lname
from tblcust c
left join tblmname m on c.id = m.cid
If condition is true then
+ @val +
left join tbllname on l.id = c.id
How to concatinate user defined variable in select clause?
Thanks in advance,
Govind
Comment