Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > query w/ case help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-12-04, 17:58
hueby hueby is offline
Registered User
 
Join Date: Aug 2004
Location: STL
Posts: 45
query w/ case help

Hey all, here is my problem: I want to run a query to grab all the 'next dates' from a column after the user inputs a date. .. and then repeat accordingly.

Here is some simplified example code: This works fine (but doesn't grab all rows, which varies, with the Date. It only grabs the first, hence the 'top 1')

Code:
select top 1 datewrk from hours where datewrk is not null and datewrk > '06/15/2004' and purchord = '4112' order by datewrk

Soo, then this grabs all the rows with the Date, but doesn't 'skip' correctly. If you pick the date right before a valid row, as in there are rows of data for Date 6/18/2004 and you pick 6/17/2004 it will bring up the next date fine. BUT if you pick 6/15/2004 it will not 'skip ahead'. Any ideas??? Thanks

Code:
select datewrk from hours where datewrk is not null and datewrk > '06/15/2004' and 1 = (case when Datewrk = (select min(Datewrk) from Hours where Datewrk is not null and Datewrk > '06/15/2004') then 1 else 0 end) and purchord = '4112' order by datewrk
Reply With Quote
  #2 (permalink)  
Old 10-12-04, 19:43
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 9,570
Does this work:
Code:
SELECT datewrk FROM hours WHERE datewrk IS NOT NULL AND datewrk > '06/15/2004' AND purchord = '4112' AND 1 = (case when Datewrk = (select min(Datewrk) FROM Hours WHERE Datewrk IS NOT NULL AND purchord = '4112' AND Datewrk > '06/15/2004') THEN 1 ELSE 0 END) ORDER BY datewrk
-PatP
Reply With Quote
  #3 (permalink)  
Old 10-13-04, 11:14
hueby hueby is offline
Registered User
 
Join Date: Aug 2004
Location: STL
Posts: 45
Thumbs up

Yes, that works! THANK YOU.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On