| Author | Topic | 
                            
                                    | dougancilPosting Yak  Master
 
 
                                        217 Posts | 
                                            
                                            |  Posted - 2010-10-25 : 10:59:31 
 |  
                                            | I have the following query:select	a.MyDate,	Sunday = dateadd(dd,((datediff(dd,'17530107',a.MyDate)/7)*7)+7,'17530107')from	( -- Test Data	select MyDate = convert(datetime,'20100930')	) aand what I'd like to do is instead of offering a datetime, I have a SQL field that I need to pull from with the date. Can anyone offer me a suggestion on how to do that? What I see changing is the select MyDate = [exceptions].exceptiondate. I tried that though and I get an error:The column prefix 'exceptions' does not match with a table name or alias name used in the query.Thank you,Doug |  | 
       
                            
                       
                          
                            
                                    | pk_bohraMaster Smack Fu Yak Hacker
 
 
                                    1182 Posts | 
                                        
                                          |  Posted - 2010-10-25 : 12:38:06 
 |  
                                          | quote:Can you show us the query you have tried. May be a minor mistake which can be corrected.Regards,BohraI am here to learn from Masters and help new bees in learning.select MyDate = [exceptions].exceptiondate. I tried that though and I get an error:The column prefix 'exceptions' does not match with a table name or alias name used in the query.Thank you,Doug
 
 |  
                                          |  |  | 
                            
                       
                          
                            
                                    | dougancilPosting Yak  Master
 
 
                                    217 Posts | 
                                        
                                          |  Posted - 2010-10-25 : 12:56:11 
 |  
                                          | Bohra,Here's the query I just tried:select	a.MyDate,	Sunday = dateadd(dd,((datediff(dd,'17530107',a.MyDate)/7)*7)+7,'17530107')from	( -- Test Data	select MyDate = [payroll].payrolldate	) awhich returns an error back to me:The column prefix 'payroll' does not match with a table name or alias name used in the query.I've also tried this query:select	a.MyDate,	Sunday = dateadd(dd,((datediff(dd,'17530107',a.MyDate)/7)*7)+7,'17530107')from	( -- Test Data	select MyDate = payrolldate	) awhich returns this error back to me:Invalid column name 'payrolldate'. |  
                                          |  |  | 
                            
                       
                          
                            
                                    | dougancilPosting Yak  Master
 
 
                                    217 Posts | 
                                        
                                          |  Posted - 2010-10-25 : 12:57:51 
 |  
                                          | I apologize this question should be in the T-SQL forum. |  
                                          |  |  | 
                            
                       
                          
                            
                                    | tkizerAlmighty SQL Goddess
 
 
                                    38200 Posts |  | 
                            
                       
                          
                            
                                    | dougancilPosting Yak  Master
 
 
                                    217 Posts | 
                                        
                                          |  Posted - 2010-10-25 : 15:02:26 
 |  
                                          | Thanks Tara. |  
                                          |  |  | 
                            
                       
                          
                            
                                    | pk_bohraMaster Smack Fu Yak Hacker
 
 
                                    1182 Posts | 
                                        
                                          |  Posted - 2010-10-26 : 01:30:48 
 |  
                                          | quote:Originally posted by dougancil
 select	a.MyDate,	Sunday = dateadd(dd,((datediff(dd,'17530107',a.MyDate)/7)*7)+7,'17530107')from	( -- Test Data	select MyDate =
 [payroll].payrolldate from payroll	) a
 |  
                                          |  |  | 
                            
                       
                          
                            
                                    | dougancilPosting Yak  Master
 
 
                                    217 Posts | 
                                        
                                          |  Posted - 2010-10-26 : 10:45:43 
 |  
                                          | Bohra,I tried your query:select	a.MyDate,	Sunday = dateadd(dd,((datediff(dd,'17530107',a.MyDate)/7)*7)+7,'17530107')from	( -- Test Data	select MyDate payrolldate from payroll	) aand got this error:Server: Msg 207, Level 16, State 3, Line 1Invalid column name 'MyDate'.Server: Msg 207, Level 16, State 1, Line 1Invalid column name 'MyDate'.Server: Msg 207, Level 16, State 1, Line 1Invalid column name 'MyDate'. |  
                                          |  |  | 
                            
                       
                          
                            
                                    | dougancilPosting Yak  Master
 
 
                                    217 Posts | 
                                        
                                          |  Posted - 2010-10-26 : 13:50:16 
 |  
                                          | Ok so with some help, here is what I have now. select payrolldate,   Sunday = dateadd(dd, ((datediff(dd, '17530107', payrolldate)/7)*7)+7, '17530107')from payrollBut what I want to make sure of is that when my query is run, that it picks the latest date in payrolldate to run against and not return the values back for all the entries. Can anyone help me think of a way to do this? Thank youDoug |  
                                          |  |  | 
                            
                       
                          
                            
                                    | pk_bohraMaster Smack Fu Yak Hacker
 
 
                                    1182 Posts | 
                                        
                                          |  Posted - 2010-10-26 : 13:54:13 
 |  
                                          | quote:You missed the = equal to symbol. I just striked Payroll. and not = payroll.Anyhow try the below exampleCreate table Payroll(payrolldate datetime )Insert into PayrollSelect getdate()selecta.MyDate,Sunday = dateadd(dd,((datediff(dd,'17530107',a.MyDate)/7)*7)+7,'17530107')from( -- Test Dataselect MyDate = payrolldate from payroll) aOriginally posted by dougancil
 Bohra,I tried your query:select	a.MyDate,	Sunday = dateadd(dd,((datediff(dd,'17530107',a.MyDate)/7)*7)+7,'17530107')from	( -- Test Data	select MyDate payrolldate from payroll	) aand got this error:Server: Msg 207, Level 16, State 3, Line 1Invalid column name 'MyDate'.Server: Msg 207, Level 16, State 1, Line 1Invalid column name 'MyDate'.Server: Msg 207, Level 16, State 1, Line 1Invalid column name 'MyDate'.
 
 |  
                                          |  |  | 
                            
                       
                          
                            
                                    | dougancilPosting Yak  Master
 
 
                                    217 Posts | 
                                        
                                          |  Posted - 2010-10-26 : 14:19:00 
 |  
                                          | Ok so I have a solution for this in place that I had forgotten about. I have a value in another field I can use as a "qualifier" for this data. I figured this out.Thank youDoug |  
                                          |  |  | 
                            
                       
                          
                            
                                    | pk_bohraMaster Smack Fu Yak Hacker
 
 
                                    1182 Posts | 
                                        
                                          |  Posted - 2010-10-26 : 23:05:16 
 |  
                                          | quote:You are welcomeOriginally posted by dougancil
 Ok so I have a solution for this in place that I had forgotten about. I have a value in another field I can use as a "qualifier" for this data. I figured this out.Thank youDoug
 
   |  
                                          |  |  | 
                            
                            
                                |  |