help needed urgently with datediff query

  • Hi - I have been trying to return the date diff value and keep getting an error saying:

    character constant must contain exactly one character

    This is what I am currently trying - can anyone let me know what I am doing wrong please? any help appreciated...

    return Convert.ToDecimal(microsoft.visualbasic.DateDiff(microsoft.visualbasic.DateInterval.Day, Date.Parse("[CUST_Tickets.CREATE_DATE)"), microsoft.visualbasic.Now))

    Julie

  • Trying to run a .NET statement in SSMS (?) :unsure:

  • julie 75341 (6/2/2013)


    Hi - I have been trying to return the date diff value and keep getting an error saying:

    character constant must contain exactly one character

    This is what I am currently trying - can anyone let me know what I am doing wrong please? any help appreciated...

    return Convert.ToDecimal(microsoft.visualbasic.DateDiff(microsoft.visualbasic.DateInterval.Day, Date.Parse("[CUST_Tickets.CREATE_DATE)"), microsoft.visualbasic.Now))

    Julie

    Are you doing this in a CLR proc? If not, this will not work in sql server because this is not t-sql.

    If you are looking for the t-sql equivalent of this it would be something like this.

    datediff(day, CUST_Tickets.CREATE_DATE, getdate())

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Hi and many thanks for your reply.

    That was how i had been doing it.

    .very similar anyway but then when i didnt quite get it right i asked the guy who developed the addon...its within an sddon for sage act. He swayed me towards the other way. I will revert back and see what i did wrong as your code may work if ive just missed something minor

    ...which wouldnt suprise me!

    Big thanks will report back ltr

    Julie

  • Hi and many thanks for your reply.

    That was how i had been doing it.

    .very similar anyway but then when i didnt quite get it right i asked the guy who developed the addon...its within an sddon for sage act. He swayed me towards the other way. I will revert back and see what i did wrong as your code may work if ive just missed something minor

    ...which wouldnt suprise me!

    Big thanks will report back ltr

    Julie

  • Hi - I have gone back to how I was trying before (similer to your recommendation) and only got even more errors 🙁

    I am not having much luch with this one am I !!

    Thanks for yoru help though, much appreciated 🙂

    julie

  • julie 75341 (6/2/2013)


    Hi - I have gone back to how I was trying before (similer to your recommendation) and only got even more errors 🙁

    I am not having much luch with this one am I !!

    Thanks for yoru help though, much appreciated 🙂

    julie

    Our problem is that you haven't given us enough to really help you with your problem. If you could post your code and the error message(s) you are getting I am sure we could provide you with much better answers.

  • Hi and thank you again for your reply. Sorry -my fault for not giving more info - you know what its like when you almost tear your hair out!

    Ok I want to find the day difference between the create date of a ticket (custom field in sage act) and todays date - I started with the first bit of code which was pretty much as recommended in one of the replies which was this:

    datediff(day, CUST_Tickets.CREATE_DATE, getdate())

    ...and various other options, every time I got similar to the error msg as attached

    I then tried along the lines of the below as given by the company who provided the sage act addon:

    return Convert.ToDecimal(microsoft.visualbasic.DateDiff(microsoft.visualbasic.DateInterval.Day, Date.Parse("[CUST_Tickets.CREATE_DATE)"), microsoft.visualbasic.Now))

    and I got this error...

    character constant must contain exactly one character

    I am hoping the attached screenshot may shed some light on this, I may be being really blonde so apologies if I am...ha. Thanks for all your help!

    Kind regards

    Julie

  • julie 75341 (6/2/2013)


    Hi and thank you again for your reply. Sorry -my fault for not giving more info - you know what its like when you almost tear your hair out!

    Ok I want to find the day difference between the create date of a ticket (custom field in sage act) and todays date - I started with the first bit of code which was pretty much as recommended in one of the replies which was this:

    datediff(day, CUST_Tickets.CREATE_DATE, getdate())

    ...and various other options, every time I got similar to the error msg as attached

    I then tried along the lines of the below as given by the company who provided the sage act addon:

    return Convert.ToDecimal(microsoft.visualbasic.DateDiff(microsoft.visualbasic.DateInterval.Day, Date.Parse("[CUST_Tickets.CREATE_DATE)"), microsoft.visualbasic.Now))

    and I got this error...

    character constant must contain exactly one character

    I am hoping the attached screenshot may shed some light on this, I may be being really blonde so apologies if I am...ha. Thanks for all your help!

    Kind regards

    Julie

    This isn't your code, it is a snippet. Also, where is the complete error message you are getting?

  • Hi Lynn

    The complete error msg was attached in a screenahot...thats it...all i get. Thats the screenshot within the sage act addon.

    The other ones i have tried dont look like they have pasted into my msg here and i have left the office to come home so will submit them tomorrow so you can see the entire code that i have tried..

    Thanks

    Julie

  • This does not look like SQL. What are you trying to accomplish and how?

Viewing 11 posts - 1 through 10 (of 10 total)

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