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.
    
        | 
                
                    | 
                            
                                | Author | Topic |  
                                    | TzwenStarting 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) Table1I always get the error: Invalid column name 'Typegroup' Could anyone tell me why and how can I get rid of the Error please |  |  
                                    | MIK_2008Master 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 TypeGroupCheersMIK |  
                                          |  |  |  
                                    | TzwenStarting Member
 
 
                                    7 Posts | 
                                        
                                          |  Posted - 2014-03-12 : 11:51:19 
 |  
                                          | unfortunately same error message |  
                                          |  |  |  
                                    | MIK_2008Master 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 successfullySelect *,Row_Number() over (Partition by Typegroup order by DateTime2 asc) as seqnumthis does not look like a proper select statement, I believe you should specify a table for this inner queryCheersMIK |  
                                          |  |  |  
                                    | TzwenStarting Member
 
 
                                    7 Posts | 
                                        
                                          |  Posted - 2014-03-12 : 12:16:32 
 |  
                                          | Hi!If i do Select Variablefrom(Select *,Row_Number() over (Partition by Variable order by DateTime2 asc) as seqnum) Table1it is working fine. So i thought it depends on the 'Case when ...' Statement. How would you specify a table there? |  
                                          |  |  |  
                                    | MIK_2008Master 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.CheersMIK |  
                                          |  |  |  
                                |  |  |  |