SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Access to Case When generated fields
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Tzwen
Starting Member

7 Posts

Posted - 03/12/2014 :  10:57:14  Show Profile  Reply with Quote
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

Edited by - Tzwen on 03/12/2014 11:51:48

MIK_2008
Flowing Fount of Yak Knowledge

Pakistan
1052 Posts

Posted - 03/12/2014 :  11:15:06  Show Profile  Reply with Quote
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 - 03/12/2014 :  11:51:19  Show Profile  Reply with Quote
unfortunately same error message
Go to Top of Page

MIK_2008
Flowing Fount of Yak Knowledge

Pakistan
1052 Posts

Posted - 03/12/2014 :  11:59:24  Show Profile  Reply with Quote
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 - 03/12/2014 :  12:16:32  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Pakistan
1052 Posts

Posted - 03/12/2014 :  12:44:16  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000