Solved

SQL Syntax for Date

Posted on 2012-03-12
8
326 Views
Last Modified: 2012-03-12
Dear Experts

I have a recordset within dreamweaver as follows:

SELECT *
FROM dbo.propertylistingresults_col
WHERE pPrice <= MMColParam and pPrice >= MMColParam1 and (GETDATE() - pDateEntered) < MMColParam2

However when trying to display the page I receive the following error message:



Microsoft OLE DB Provider for ODBC Drivers

 error '80040e57'

[Microsoft][SQL Server Native Client 10.0][SQL Server]Arithmetic overflow error converting expression to data type datetime.
 
/propertyresults_quick.asp, line 37


Can anyone advise me how to amend the necessery within the recordset SQL query to eliminate this.

Thanks
0
Comment
Question by:grantballantyne
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 8

Expert Comment

by:venk_r
ID: 37710148
Please use Datediff or Dataddd function instead of (GETDATE() - pDateEntered) for comparison.
Its always safe to use them.
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 37710158
are you trying to do some date calculations?

What data type is pDateEntered and MMColParam2?
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 37710177
You've got a value in "pDateEntered" that is not a valid datetime.


SELECT *
FROM dbo.propertylistingresults_col
WHERE
    pPrice <= MMColParam AND
    pPrice >= MMColParam1 AND
    1 = CASE
        WHEN ISDATE(pDateEntered) = 0 THEN 0
        WHEN (GETDATE() - pDateEntered) < MMColParam2 THEN 1
        ELSE 0 END
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

Author Comment

by:grantballantyne
ID: 37710182
Hi

pDateEntered is Date and MMColparam2 is numeric.

What I am trying to calculate is the number of days between the to dates to a numeric figure and then return the records where the result is < MMColParam2

Thanks
0
 

Author Comment

by:grantballantyne
ID: 37710203
Hi

I tried the syntax above but still get the error:

Microsoft OLE DB Provider for ODBC Drivers error '80040e57'

[Microsoft][SQL Server Native Client 10.0][SQL Server]Arithmetic overflow error converting expression to data type datetime.

/propertyresults_quick.asp, line 37



Thanks
0
 
LVL 15

Expert Comment

by:Ess Kay
ID: 37710205
use cast or convert to varchar, and the trim the line to the first 10 letters

instead of the full dat 10/10/2012 01:30:33 it will just be 10/10/2012

read more here

http://www.sqlusa.com/bestpractices/datetimeconversion/
http://linesofcode.net/snippets/45
http://anubhavg.wordpress.com/2009/06/11/how-to-format-datetime-date-in-sql-server-2005/
http://www.w3schools.com/sql/sql_dates.asp
0
 
LVL 28

Accepted Solution

by:
sammySeltzer earned 500 total points
ID: 37710261
You try this assuming you want minutes and seconds as well.

WHEN convert(varchar,GETDATE()) - convert(varchar,pDateEntered)) < MMColParam2 THEN 1
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 37710280
???

That's not even a valid operation.
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

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

831 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