Home Forums SQL Server 2008 T-SQL (SS2K8) Problem with CAST to VARCHAR with SUBSTRING Function RE: Problem with CAST to VARCHAR with SUBSTRING Function

  • 16 posts into what should have been a 1-2 post answer if ddl and sample data were provided...

    Here is my last shot in the dark.

    SELECT

    CASE LEFT(cast(Customer.STARTDATE as varchar(20)), 2)

    WHEN '98' THEN substring(cast(Customer.STARTDATE as varchar(20)), 3, 2)

    WHEN '99' THEN substring(cast(Customer.STARTDATE as varchar(20)), 3, 2)

    END AS LossMo

    FROM

    dbo.Customer

    If this doesn't help you may want to turn up the lights for the rest of us. The light switch is in ddl, sample data and desired output as outlined in the link your signature. Feel free to read the same article at the first link in my signature. If that doesn't help try reading the article here. http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx.

    _______________________________________________________________

    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/