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 2012 Forums
 Transact-SQL (2012)
 Access to Case When generated fields

Author  Topic 

Tzwen
Starting Member

7 Posts

Posted - 2014-03-12 : 10:57:14
Hello,

I have the following lines in my (working) query:

Select (Case When Date_Time <= DateTime2 Then 1 Else 2 END) as 'Typegroup'
from(
Select *,
Row_Number() over (Partition by Typegroup order by DateTime2 asc) as seqnum) Table1

I always get the error: Invalid column name 'Typegroup' Could anyone tell me why and how can I get rid of the Error please

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2014-03-12 : 11:15:06
remove the single quote and check ..
e.g.
replace -> as 'typegroup
with -> as TypeGroup



Cheers
MIK
Go to Top of Page

Tzwen
Starting Member

7 Posts

Posted - 2014-03-12 : 11:51:19
unfortunately same error message
Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2014-03-12 : 11:59:24
Ah, where is the from clause in the sub query .. does the following query executes successfully

Select *,
Row_Number() over (Partition by Typegroup order by DateTime2 asc) as seqnum


this does not look like a proper select statement, I believe you should specify a table for this inner query



Cheers
MIK
Go to Top of Page

Tzwen
Starting Member

7 Posts

Posted - 2014-03-12 : 12:16:32
Hi!

If i do
Select Variable
from(
Select *,
Row_Number() over (Partition by Variable order by DateTime2 asc) as seqnum) Table1

it is working fine. So i thought it depends on the 'Case when ...' Statement. How would you specify a table there?
Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2014-03-12 : 12:44:16
Case looks good to me ..

A simply but complete query is generally "SELECT columnNames FROM TableName". I don't see the table in the inner query. if you say its working fine then okay .. then the error could be due to the "Partition by Typegroup order by DateTime2 asc". SQL is unable to find this column. but still I wonder how could you run an inner join without specifying a table name in the inner query.

Cheers
MIK
Go to Top of Page
   

- Advertisement -