Consulting

Results 1 to 4 of 4

Thread: Solved: Convert Varchar to Date format

  1. #1
    VBAX Regular
    Joined
    May 2008
    Posts
    46
    Location

    Solved: Convert Varchar to Date format

    I have a really crappy database where one column is a date, but it's not formatted as a date (not sure what the format is, but I think it's varchar). I want to use SQL code to format it as a date when I pull the query so it will sort correctly. The following is my query that doesn't work: The red part is the field that needs to be a date.


    SELECT agent.ssno, WS_TRACKER.AGENT, agent.Supervisor, convert(varchar,WS_TRACKER.DATE_ENT,101), WS_TRACKER.Bpartner, WS_TRACKER.CUS_NAME, WS_TRACKER.IO_NUM, WS_TRACKER.WS_CITY, convert(varchar(10),WS_TRACKER.WS_DATE,101) AS 'Workshop_Date', WS_TRACKER.CERT_TYPE
    FROM STRATADIAL.dbo.agent agent, STRATADIAL.dbo.WS_TRACKER WS_TRACKER
    WHERE WS_TRACKER.AGENT = agent.name AND ((WS_TRACKER.DATE_ENT>={ts '2009-10-01 00:00:00'}))
    ORDER BY WS_TRACKER.WS_DATE, WS_TRACKER.DATE_ENT, WS_TRACKER.CERT_TYPE
    ________________________________________
    The more questions I ask and the more I learn, I realize that I don't know squat!!!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Doesn't SQL Server do an implicit conversion if it is a valid date?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    May 2008
    Posts
    46
    Location
    I don't know, but when I run the query it does not sort correctly.
    ________________________________________
    The more questions I ask and the more I learn, I realize that I don't know squat!!!

  4. #4
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    seems if it is a timestamp there is no need for convert() as that will screw up a sort. What if you just use


    [vba]
    SELECT agent.ssno, WS_TRACKER.AGENT, agent.Supervisor,WS_TRACKER.DATE_ENT, WS_TRACKER.Bpartner, WS_TRACKER.CUS_NAME, WS_TRACKER.IO_NUM, WS_TRACKER.WS_CITY, WS_TRACKER.WS_DATE, WS_TRACKER.CERT_TYPE
    FROM STRATADIAL.dbo.agent agent, STRATADIAL.dbo.WS_TRACKER WS_TRACKER
    WHERE WS_TRACKER.AGENT = agent.name AND ((WS_TRACKER.DATE_ENT>='10/1/2009'))
    ORDER BY WS_TRACKER.WS_DATE, WS_TRACKER.DATE_ENT, WS_TRACKER.CERT_TYPE
    [/vba]

    .02 Stan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •