| 
                
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 |  
                                    | DB AnalystStarting Member
 
 
                                        8 Posts | 
                                            
                                            |  Posted - 2011-02-23 : 10:02:39 
 |  
                                            | Hi everyone,In the below query I'm working on, I'm trying to get 3 things from all the joined tables:  the CUSTOMER_ACCOUNT_ID, the transaction date in the form (YYYYMM), and the sum of the total transaction amounts.Note the GROUP BY statement as the second-to-last line.  SQL Server does not seem to like the "PERIOD" variable, although it is referenced in the SELECT statement.  The error indicates, "Invalid column name".Any help you can give me regarding this problem would be appreciated.  Thanks!*******************************************select  cal.customer_account_id,(SELECT YEAR(txn_date)*100 + MONTH(txn_date)) AS PERIOD,sum(txn_amount_base)from    transactions tjoin    customer_account_link calon      t.account_id = cal.account_idand     txn_id in (        select  txn_id        from    transactions t        join    keyword k        on      UPPER(t.customer_name) like '%' + k.keyword + '%'        or      UPPER(t.originator_name) like '%' + k.keyword + '%')group by cal.customer_account_id, PERIODhaving  sum(txn_amount_base) > 750 |  |  
                                    | webfredMaster Smack Fu Yak Hacker
 
 
                                    8781 Posts | 
                                        
                                          |  Posted - 2011-02-23 : 10:38:57 
 |  
                                          | group by cal.customer_account_id, YEAR(txn_date)*100 + MONTH(txn_date) No, you're never too old to Yak'n'Roll if you're too young to die.
 |  
                                          |  |  |  
                                    | DB AnalystStarting Member
 
 
                                    8 Posts | 
                                        
                                          |  Posted - 2011-03-03 : 11:04:48 
 |  
                                          | OK.  I did it slightly differently, and it worked.CONVERT(CHAR(6), TXN_DATE, 112) AS PERIODand thengroup by CONVERT(CHAR(6), TXN_DATE, 112) |  
                                          |  |  |  
                                |  |  |  |  |  |