Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return data for present day using case? 2

Status
Not open for further replies.
Jul 21, 2009
13
US
Hi,

I'm really new to SQL. I am trying to set up a query that runs automatically daily to pull any data populated in a table for the present day (not just for today but ongoing daily). I do not want to have to have to update the date in the query daily. The table only populates with codes of jobs ran that day with a timestamp for each code.

So for today (7/22) we might have codes A and C, and yesterday we might have had A, B, and C. I want to be able to use case statements to designate substitue values for the codes and produce results so if A and C were run TODAY, then the query would return: Report A and Report C were run today. The table also has all historical runs and I want to ignore anything before the present day.

i.e. table has following data

Time Code
2009-07-21 17:35:02:597 A
2009-07-21 18:35:02:597 B
2009-07-21 19:35:02:597 C
2009-07-22 17:35:02:597 A
2009-07-22 19:35:02:597 C

Would really appreciate the help!!
 
Code:
select * 
from [Table]
where dateadd(dd,0,datediff(dd,0,[DateField])) = dateadd(dd,0,datediff(dd,0,getdate()))
 
Code:
declare @Today datetime, @Tomorrow datetime

set @Today = DATEADD(DAY, 0, DATEDIFF(DAY, 0, CURRENT_TIMESTAMP))

set @Tomorrow = DATEADD(DAY, 1, DATEDIFF(DAY, 0, CURRENT_TIMESTAMP))

select * from myTable where DateField >=@Today and DateField < @Tomorrow
 
Thanks all. Can you also help me figure out how to return multiple values but using a case statement substitute those values with another value. i.e. if codes A and C were run today, i want to be able to substitute Apple for A and Cat for C and output:
The following reports were output today:
Apple
Cat


Thanks again!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top