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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Pulling only stats by days

Author  Topic 

tranquilraven
Starting Member

19 Posts

Posted - 2012-06-07 : 17:20:40
Is it possible to pull only items with todays date? The date column is formatted as Date, so it pulls date and time. I want to just pull the data for each day, so like todays reports are today's date, tomorrow it will pull tomorrows data, etc.


SELECT OrderDate AS 'Order Date',
PaymentAmount AS 'Total Payments',
TotalShippingCost AS 'Shipping Received',
SalesTax1 AS 'Sales Tax Received',
PaymentDeclined AS ' Payment Declined'
FROM Orders
WHERE PaymentDeclined IS NULL
ORDER BY OrderDate DESC

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-06-07 : 17:31:17
[code]SELECT
OrderDate AS 'Order Date',
PaymentAmount AS 'Total Payments',
TotalShippingCost AS 'Shipping Received',
SalesTax1 AS 'Sales Tax Received',
PaymentDeclined AS ' Payment Declined'
FROM
Orders
WHERE
PaymentDeclined IS NULL
AND OrderDate >= CAST(SYSDATETIME() AS DATE)
AND OrderDate < DATEADD(DAY, 1, CAST(SYSDATETIME() AS DATE))
ORDER BY
OrderDate DESC[/code]
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-06-07 : 22:28:36
quote:
Originally posted by Lamprey

SELECT 
OrderDate AS 'Order Date',
PaymentAmount AS 'Total Payments',
TotalShippingCost AS 'Shipping Received',
SalesTax1 AS 'Sales Tax Received',
PaymentDeclined AS ' Payment Declined'
FROM
Orders
WHERE
PaymentDeclined IS NULL
AND OrderDate >= CAST(SYSDATETIME() AS DATE)
AND OrderDate < DATEADD(DAY, 1, CAST(SYSDATETIME() AS DATE))
ORDER BY
OrderDate DESC



is there any advantage of using SYSDATETIME over GETDATE in above scenario as anyways we're comparing against a open close interval.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -