CONVERT(VARCHAR(10) not working

  • Trying to convert datetime to varchar(10), typical stuff. Only problem is, it's not working. This first example works fine:

    select top 1 convert(varchar(10),createdon, 101)

    from tracking

    But when I have it - the same way - in another query, it returns it as a datetime value.

    Id_OrderNumber_ReferralNumber=lb.orderno,

    Id_ShipDate=convert(varchar(10),tr.createdon,101),

    Id_OrderDate=convert(varchar(10),ot.createdon,101),

    Id_FirstPatientShipDate=convert(varchar(10),fs.FirstShip,101),

    Any ideas?

    Randy

  • what does "not working" mean to you? you did not mention any errors, and convert(varchar will return a string, albeit maybe a string that looks like a date, but it cannot return datetime.

    if you assign it or insert it into a datetime column, it might implicitly convert from string to date time, is that what you are seeing?

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Remember that CONVERT won't reformat a string. The column needs to be a date/time data type to allow CONVERT apply the format code.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 3 posts - 1 through 2 (of 2 total)

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