Solved

sql datediff returning wrong number

Posted on 2014-07-21
5
173 Views
Last Modified: 2014-07-21
In the attachment you can see the code and the results the Months columin is wrong, not sure why. Capture.PNG
0
Comment
Question by:rschmehl
  • 3
5 Comments
 
LVL 65

Assisted Solution

by:Jim Horn
Jim Horn earned 250 total points
Comment Utility
<wild guess>

You can't use one column in a SELECT clause in an expression in another column in the SELECT clause.

So .. the Months calculation, where it references MC.MemberCoverateTerminationDate, is using the column value and not the calculated value in the previous column.

Otherwise, the datediff looks correct.
0
 
LVL 34

Accepted Solution

by:
Brian Crowe earned 250 total points
Comment Utility
My assumption is in line with Jim Horn's and the majority of your MemberCoverageTerminationDate values are far off in the future somewhere around 1/1/2079.  Add the unmanipulated MemberCoverageTerminationDate to your select list to see what is actually being calculated.
0
 

Author Comment

by:rschmehl
Comment Utility
you aare right, i did just that and the 4 dates in the table are off   . i.e. 1978 for some reason  so you are both right. Thanks you very much
0
 

Author Comment

by:rschmehl
Comment Utility
I've requested that this question be closed as follows:

Accepted answer: 0 points for rschmehl's comment #a40209793
Assisted answer: 250 points for Jim Horn's comment #a40209578
Assisted answer: 250 points for Brian Crowe's comment #a40209595

for the following reason:

Jim and Brian are both rigtt
0
 

Author Closing Comment

by:rschmehl
Comment Utility
They were right. thank you
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now