SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Pulling only stats by days
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

tranquilraven
Starting Member

19 Posts

Posted - 06/07/2012 :  17:20:40  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3821 Posts

Posted - 06/07/2012 :  17:31:17  Show Profile  Reply with Quote
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
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47023 Posts

Posted - 06/07/2012 :  22:28:36  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000