Home Forums SQL Server 2008 T-SQL (SS2K8) varchar to time or datetime or ARGGHH Please help me. RE: varchar to time or datetime or ARGGHH Please help me.

  • nicoleaslater (9/26/2012)


    I have a datetime (your standard yyyy-mm-dd hh:mm:ss) column and a varchar column that holds an appt time that looks like this: 1030 or 0735. I need to be able to calculate a difference to determine a wait time. I've tried cast and convert, I keep getting an error: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. I was thinking integers?

    I really haven't a clue where to go from here. Please help.

    The struggles you are facing is EXACTLY why you should always use the proper datatypes. Datetime data should always be stored in a datetime column. Of course this is sometimes way beyond our control and we have to plug our noses and push forward. So in the name of plugging my nose and helping I need to get some more details from you.

    Can you post ddl (create table statements) and some sample data (insert statements) along with desired output based on your sample data. You do not need to post a lot of data but at least a few rows to demonstrate your data.

    _______________________________________________________________

    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/