October 4, 2009 at 7:27 am
Hello
I have a couple of issues I cannot get my head around 🙁
1. I have invoice.InvDate and what I would like to do in a query is show how old this invoice is in days?
2. I also have another query I am searching on balance values between -1.00 and 1.00 but I want to exclude any values that = 0.00.
I am new to this sort of queries and have written CR reports with these included but I need to set up these in SQL as a query and at some point a view.
I am using both SQL 2000 Ent Edition and 2005 Std Edition and I would be greatfull if some one could point me in the right direction
Thanks in advance
October 4, 2009 at 7:53 am
Look up the DATEDIFF function in Books On Line at:
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/57e0601a-9d97-4437-9be1-7efa639b39fc.htm
The GETDATE function reference is:
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/bebe3b65-2b3e-4c73-bf80-ff1132c680a7.htm
The following will returrn a value of 3 as today is 10/04/09
.
SELECT DATEDIFF(day, '10/01/09', GETDATE())
Of course you would replace my hard coded 10/01/09 with the value retrieved from your table
SELECT DATEDIFF(Day,yourtable.datecolumn,GETDATE())
For the balance question experiment with:
CREATE TABLE #TT
(Id INT ,Balance MONEY)
INSERT INTO #TT
SELECT 1,$0.00 UNION ALL
SELECT 2,$1.00 UNION ALL
SELECT 3, $-1.00 UNION ALL
SELECT 4,$500.00 UNION ALL
SELECT 5,$.55
SELECT * FROM #TT WHERE (BALANCE BETWEEN -1.00 AND 1) AND BALANCE <> 0.0000
Which will give you:
IdBalance
21.00
3-1.00
50.55
An explanation BETWEEN can be found at:
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/a5d5b050-203e-4355-ac85-e08ef5ca7823.htm
October 4, 2009 at 8:09 am
Thanks for the reply, I will have a play with these and let you know.
Thanks Agian
Graham
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply