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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Invalid column name as a referenced column

Author  Topic 

eric@horwitzlaw.com
Starting Member

6 Posts

Posted - 2005-04-08 : 13:41:31
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.

THANKS
Eric

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 COL1
Or, you put the 1st set of aliased expressions in a derived table, and select out of that

i.e.

Select replace(replace(COL1,'Injury','SOMETHING'),'WC','SOMETHING2')
From
(
select replace(replace(typelaw,7,'Injury'),9,'WC') as 'COL1'
) dt
Go to Top of Page
   

- Advertisement -