473,465 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

using a query to return the next Sunday

347 Contributor
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')
) a

and 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
Oct 25 '10 #1

✓ answered by ck9663

This

Expand|Select|Wrap|Line Numbers
  1.  
  2. select MyDate = [exceptions].exceptiondate. 
  3.  
  4.  
has to be a complete subquery. If your intention is to get it from a table, do a

Expand|Select|Wrap|Line Numbers
  1.  
  2. select MyDate = exceptiondate
  3. from exceptions
  4.  
  5.  
or a straight forward:

Expand|Select|Wrap|Line Numbers
  1.  
  2. select
  3. exceptiondate, 
  4. Sunday = dateadd(dd,((datediff(dd,'17530107',exceptiondate)/7)*7)+7,'17530107')
  5. from exceptions
  6.  
Good Luck!!!

~~ CK

3 3744
ck9663
2,878 Recognized Expert Specialist
This

Expand|Select|Wrap|Line Numbers
  1.  
  2. select MyDate = [exceptions].exceptiondate. 
  3.  
  4.  
has to be a complete subquery. If your intention is to get it from a table, do a

Expand|Select|Wrap|Line Numbers
  1.  
  2. select MyDate = exceptiondate
  3. from exceptions
  4.  
  5.  
or a straight forward:

Expand|Select|Wrap|Line Numbers
  1.  
  2. select
  3. exceptiondate, 
  4. Sunday = dateadd(dd,((datediff(dd,'17530107',exceptiondate)/7)*7)+7,'17530107')
  5. from exceptions
  6.  
Good Luck!!!

~~ CK
Oct 26 '10 #2
dougancil
347 Contributor
CK,

here's what I went with:

select payrolldate,
Sunday = dateadd(dd, ((datediff(dd, '17530107', payrolldate)/7)*7)+7, '17530107')
from payroll
where payrollran = 'no'

that returns the value that I need back to me.
Oct 26 '10 #3
ck9663
2,878 Recognized Expert Specialist
Yes, the straight forward option....Am glad you made it to work...

Happy Coding!!!

~~ CK
Oct 26 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: J. Muenchbourg | last post by:
Looking thru my resources, I cannot find a simple way of displaying next sunday's date depending on what todays date is. I'd like to do it without doing 7 if statements or case select: ...
5
by: Petr Bravenec | last post by:
I have found that when I use the RETURN NEXT command in recursive function, not all records are returned. The only records I can obtain from function are records from the highest level of...
1
by: anshul | last post by:
Can somebody tell me about state management in asp.net using Query Strings. I am just unable to understand this. Anshul
1
by: CSN | last post by:
Is it possible to reverse the order of items returned from a plpgaql function that uses RETURN NEXT? (order by col isn't what I want) select * from my_function(); ...
18
by: A.M | last post by:
Hi, Is there any way to call a WSS web service method by using browser and see the XML result in browser as well? I have been told that there is query string syntax for calling...
2
by: Bryan_Cockrell | last post by:
Hi World, I am extracting text from an ebcdic header using dd in the cygwin environment (bash/ksh) as below in order to rename the file to something intelligent. I'm using a specific string...
6
khalidbaloch
by: khalidbaloch | last post by:
i want to show on page the messege that say there is currently no item when a mysql query return no record instead of blank page .. i hope this is not a big issue and will be resolved in first reply...
0
by: =?Utf-8?B?VG9ueSBBLg==?= | last post by:
I'm trying to develop a parameter query using Query Builder, the database is Access 2003. I placed a ? in the column to we quered and linked it to a checkbox on the form. When the user selects an...
1
by: viper888 | last post by:
Hi there, How can I automate may database backup using query analyser? My routine goes this way: 1. Every 5:00pm check Enterprise manager who is currenlty logged on to sql server. 2. If there...
2
by: kkshansid | last post by:
same query return rows in mysql but not on php page while($rs = mysql_fetch_array($sql2)) { $town=$rs; $q="select * from institute where address like '%".$town."%'";//this query //echo $town;...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.