Solved

sql datediff returning wrong number

Posted on 2014-07-21
5
178 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

Suggested Solutions

Title # Comments Views Activity
SQL Server 2012 r2 - Query results have 2 seperate results instead of 1 2 22
Sql server insert 13 30
2016 SQL Licensing 7 41
Sql server function help 15 30
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

778 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