Solved

sql datediff returning wrong number

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
TSQL Challenge... 7 37
how to just get time from a date 6 34
Error when creating an UPDATE Trigger in SQL 6 22
Shrink multiple databases at once 4 29
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
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.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
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.

828 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