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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 join on derived column from case statement doesnot

Author  Topic 

Kimi86
Yak Posting Veteran

79 Posts

Posted - 2012-07-12 : 09:34:37
I am creating a view joining many table. One of the columnis being derieved from one of the columns using simple case statement and then i need to join some other table with this new derieved column... But the join is not working even though there is no error when i execute.. any iseas??

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-07-12 : 09:40:22
Post the code you have used

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-12 : 10:12:18
you need to form a derived table and then use it in join

like

SELECT ...
FROM (SELECT othercolumn,CASE WHEN .... AS yourderivedcol,... FROM yourtable) dt
JOIN Yourothertable t
ON t.col = dt.derviedcol
...


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Kimi86
Yak Posting Veteran

79 Posts

Posted - 2012-07-12 : 10:24:17
bang on reply... This is what i eventually ended up doing but just wanted to confirm .. thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-12 : 11:06:50
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -