Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

sql datediff returning wrong number

Posted on 2014-07-21
5
Medium Priority
?
199 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 66

Assisted Solution

by:Jim Horn
Jim Horn earned 1000 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 1000 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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.

670 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