Solved

sql datediff returning wrong number

Posted on 2014-07-21
5
174 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
ID: 40209578
<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
ID: 40209595
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
ID: 40209793
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
ID: 40209840
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
ID: 40209841
They were right. thank you
0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

863 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

20 Experts available now in Live!

Get 1:1 Help Now