Link to home
Start Free TrialLog in
Avatar of jana
janaFlag for United States of America

asked on

Display days passed in decimal or integer in Ms SQL 2005 script

We have a script that displays the difference between LastDate and FirstDate, but we can't get it to display a integer value, it display a Date format value.
Avatar of jana
jana
Flag of United States of America image

ASKER

The script like a Accounts Receivables script:


DECLARE @ReportDate AS DATETIME
DECLARE @TimePass AS DECIMAL
SET @ReportDate = '20111231'
SET @TimePass = 30

SELECT FirstDate, LastDate, (LastDate-FirstDate)   FROM RM20101
WHERE LastDate <=@ReportDate
AND   (LastDate-FirstDate) > @TimePass

Open in new window


The problem is that the value displayed by "(LastDate-FirstDate)" is in Date Format.  Example (noticed the difference column):

FirstDate               LastDate                Differences
----------------------- ----------------------- -----------------------
2016-02-20 00:00:00.000 2016-03-22 00:00:00.000 1900-02-01 00:00:00.000
2016-03-27 00:00:00.000 1900-01-01 00:00:00.000 1783-10-07 00:00:00.000
2014-01-21 00:00:00.000 2014-02-20 00:00:00.000 1900-01-31 00:00:00.000

Open in new window

Avatar of jana

ASKER

Where is the script going wrong?
ASKER CERTIFIED SOLUTION
Avatar of ralmada
ralmada
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jana

ASKER

Thank you very Much!!!!!