Board index » delphi » SQL Server: column_alias not allowed in WHERE clause

SQL Server: column_alias not allowed in WHERE clause

Hello,

let's say that we have a T-SQL query like this
SELECT <some fields>, <expression> AS MyField, <expression_1> AS  MyField_1
FROM <some_tables> WHERE <expression_2>

My problem is that MyField is part of expression_1  and expression_2
contains also fields MyField and MyField_1 but Transact-SQL does not allow
column aliases as part of WHERE clause....
What can i do? This problem occured when porting SQL code from Sybase into
SQL Server

Best regards,
Lucian Chiriac

 

Re:SQL Server: column_alias not allowed in WHERE clause


Hello,
I guess you have to re- write expression_2 starting from the fields in the
tables
(replace MYField with expression and MyField_1 with expression_1)
no matter how much you hate to do this.

Regards,
Laura

Quote
Lucian Chiriac <lchir...@totalsoft.ro> wrote in message

news:8ogjvv$hu11@bornews.borland.com...
Quote
> Hello,

> let's say that we have a T-SQL query like this
> SELECT <some fields>, <expression> AS MyField, <expression_1> AS
MyField_1
> FROM <some_tables> WHERE <expression_2>

> My problem is that MyField is part of expression_1  and expression_2
> contains also fields MyField and MyField_1 but Transact-SQL does not allow
> column aliases as part of WHERE clause....
> What can i do? This problem occured when porting SQL code from Sybase into
> SQL Server

> Best regards,
> Lucian Chiriac

Other Threads