0

Why cant I use alias name as value in where clause in subquery. Is there another way to use alias in similar way in this example?

SELECT 
tm.att1 as aliasName1,

tm.att2 as aliasName2,

CASE WHEN tm.att3='A1' THEN 'A' WHEN tm.att3='B1' THEN 'B' ELSE 'C' END as aliasName3,

(SELECT COLUMN FROM TABLE WHERE TABLE_ID = '9999' AND TABLE_CODE = aliasName3) as aliasName4

FROM TABLE_MAIN tm

WHERE tm.id='11111'
jarlh
  • 42,561
  • 8
  • 45
  • 63
  • You might want to include the entire query above. – Tim Biegeleisen May 12 '22 at 15:10
  • Does this answer your question? [How to use alias column name in where clause in SQL Server](https://stackoverflow.com/questions/16161938/how-to-use-alias-column-name-in-where-clause-in-sql-server) – Shmiel May 12 '22 at 15:29
  • @Shmiel no unfortunatelly, because in that case they dont associate an alias with the column name – Josip Mucak May 12 '22 at 15:35

0 Answers0