Jump to content

Alias inside of subquery?


corbin

Recommended Posts

Hello....

 

I'm trying to do:

 

SELECT col1, (CASE WHEN col2 = 1 THEN col5 WHEN col2 = 2 THEN col6) var1 FROM table1 t WHERE col3 IN (SELECT DISTINCT col1 FROM table2 WHERE col2 = var1)

 

(Obviously replaced with bogus names ;p)

 

Anyway, I need to know if that's possible, and if it is, what the syntax is as that gives an error.

 

Thanks,

 

-Corbin

Link to comment
Share on other sites

Blerh can't edit....

 

 

Anyway, I realized I could do:

 

SELECT col1, (CASE WHEN col2 = 1 THEN col5 WHEN col2 = 2 THEN col6) var1 FROM table1 t WHERE col3 IN (SELECT DISTINCT col1 FROM table2 WHERE col2 = (CASE WHEN t1.col2 = 1 THEN t1.col5 WHEN t1.col2 = 2 THEN t1.col6))

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.