Saturday, February 25, 2012

retrieve only new customers with orders

I have a table with orders and customer info. I want to retrieve only customers with new orders only. These are the available fields: customer Id, Order Id, Order Date, and Order Subtotal. I need help with the "where" section of the query.

Hi Ray, this mainly depends on how you define "new" relative to the date values in your data. But assuming "new" means orders placed today, you could use something like "where datediff(dd,OrderDate,getdate()) = 0". You can review the SQL Server books online for more information about getdate(), datediff(), or the other date functions you could use here.

Thanks, Dean

1 comment: