Skip to content

Tag: tsql

SQL Use Value from different column on same Select

I have a question if this is possible which will save me time writing extra code and limits user error. I need to use a value from a column (which has already performed some calulcation) from the same select then do extra calculation on it. I encounter this a lot in my job. I will highlight the problem with a

SQL with non-existing column in where cause can be executed

Here’s my SQL The issue is, the colA1 does not exist in TableB. So if I just run this Then SQL Server Management Studio will return an error: Invalid column name ‘colA1’. But if it is in the where cause, the first SQL can be executed as if where cause is always true. Answer Thats because SQL…