Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hello people,I have this LONG select statement but i need to know how to reference a column that has been changed.IE. select replace(replace(typelaw,7,'Injury'),9,'WC') as 'COL1',replace(replace(COL1,'Injury','SOMETHING'),'WC','SOMETHING2')I get an error stating that COL1 is not a valid column. How would i go about doing this.THANKSEric
PW
Yak Posting Veteran
95 Posts
Posted - 2005-04-08 : 13:44:47
COL1 is a alias.You can't reference an alias in other parts of the same SQL statement. You need to replicate the entire expression that is COL1Or, you put the 1st set of aliased expressions in a derived table, and select out of thati.e.
Select replace(replace(COL1,'Injury','SOMETHING'),'WC','SOMETHING2')From( select replace(replace(typelaw,7,'Injury'),9,'WC') as 'COL1') dt