|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I REALLY need to perform a JOIN and a GROUP BY on a CASE function column alias, but I'm receiving an "Invalid column name" error when attempting to run the query. Here's a snippet:
SELECT NewColumn= CASE WHEN Table1.Name LIKE '%FOO%' THEN 'FOO TOO' END, Table2.SelectCol2 FROM Table1 JOIN Table2 ON NewColumn = Table2.ColumnName GROUP BY NewColumn, Table2.SelectCol2 ORDER BY Table2.SelectCol2 I really appreciate any help anyone can provide. Thanks, DC Ross |
|
#2
|
||||
|
||||
|
use a derived table
Code:
select DT.NewColumn
, Table2.SelectCol2
from (
select case when Name like '%FOO%'
then 'FOO TOO'
else Name
end as NewColumn
from Table1
) as DT
inner
join Table2
on DT.NewColumn = Table2.ColumnName
group
by DT.NewColumn
, Table2.SelectCol2
order
by Table2.SelectCol2
|
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Joining on and Grouping by CASE function column alias (URGENT) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|