Having problem with datetime column to execute

  • Hi

    SELECT xyz.appId, xyz.uId, xyz.appDate,

    xyz.sTId, xyz.created, xyz.createdBy

    WHERE (xyz.userId) = " & myStId _

    AND ((xyz.appDate) >= " & mySDUS _

    AND (xyz.appDate) <= " & myEDUS & ")"

    I have above query in my ASP page.

    myStId = 1

    mySDUS = '2010-7-26'

    myEDUS = '2010-7-31'

    I have table xyz, column appDate is define as datetime.

    I have many record in the table, but when I execute a this query, i am not get any result back.

    I can see there is a single quote missing around date.

    When I add single quote around date like below.

    myStId = 1

    mySDUS = "'2010-7-26'"

    myEDUS = "'2010-7-31'"

    I get following error;

    Microsoft OLE DB Provider for ODBC Drivers (0x80040E07)

    [Microsoft][ODBC SQL Server Driver][SQL Server]The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.

    Please can some one help me to sort this. I have been trying for few days and had enough of it.

    I never thought date is a big problem with sql server.

    many thanks

  • You might try wrapping the date strings in single quotes before you pass the query.

    PS: Be aware this could be dangerous.(see SQL Injection)

  • Yes, the problem is the lack of single quotes around the dates in the string.

    And yes, it is important enough that it's worth repeating: with this methodology you're basically asking someone to waltz right into your SQL Server via SQL injection. You might as well post the login instructions on your welcome page.

    └> bt



    Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • This was removed by the editor as SPAM

  • thanks

    I uesd store procedure as advice my above. But I am still getting this error;

    Microsoft OLE DB Provider for ODBC Drivers (0x80040E07)

    [Microsoft][ODBC SQL Server Driver][SQL Server]Error converting data type nvarchar to int.

    Please can someone help me out.

    many thanks

  • This was removed by the editor as SPAM

  • Ish Fad (7/29/2010)


    thanks

    I uesd store procedure as advice my above. But I am still getting this error;

    Microsoft OLE DB Provider for ODBC Drivers (0x80040E07)

    [Microsoft][ODBC SQL Server Driver][SQL Server]Error converting data type nvarchar to int.

    Please can someone help me out.

    many thanks

    What is the data type of your user id field on the table, and whats the data type of your parameter for it?

  • This was removed by the editor as SPAM

  • Hi,

    Please check ur DB datatypes and assigned datatypes whether it is matching.

    Reards

    Varun R

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply