question

gsiva_1985 avatar image
gsiva_1985 asked

How to get data as date wise.

I have a HPSM database. I have to retrieve the last 7 days open tickets count from query. can any one help.
sqlsql query
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Grant Fritchey avatar image
Grant Fritchey answered
You can use [date math][1] in the WHERE clause: DECLARE @CurrDate DATETIME = GETDATE(); SELECT ...WHERE DateColumn > DATEADD('day',-7,@CurrDate); I usually set the current date to a variable in case I need to refer to it in more than one location within the code. That way it's always consistent. [1]: http://msdn.microsoft.com/en-us/library/ms186819.aspx
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.