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
 Development Tools
 ASP.NET
 Select Case in from clause

Author  Topic 

Swati Jain
Posting Yak Master

139 Posts

Posted - 2007-10-19 : 07:47:31
Is it possible putting the condition like select case or if condition in from clause for selecting the different tables depending on the condition?How??

nr
SQLTeam MVY

12543 Posts

Posted - 2007-10-19 : 08:04:36
>> selecting the different tables
depends on what you mean.
If you want to include different tables depending on the condition then no. You can do that sort of thing using a partitioned table or view.
You tables in the query aer fixed but you can make the joins conditionally irrelevant.

select tbl1.col, col2 = coalesce(tbl2.col,tbl3.col,tbl4.col)
from tbl1
left join tbl2
on (tbl1.col = tbl2.col and @tbl = 'tbl2')
left join tbl3
on (tbl1.col = tbl3.col and @tbl = 'tbl3')
left join tbl3
on (tbl1.col = tbl4.col and @tbl = 'tbl4')




==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

ChandanJ
Starting Member

6 Posts

Posted - 2007-10-19 : 14:22:34
What exactly is your requirement?
Go to Top of Page
   

- Advertisement -