• kabaari (6/10/2014)


    Thanks! I worked through it resolve

    select b.model,

    count(case when substring(u.unitcompleted, 1,2) = '05' then 0 end) '5AM',

    count(case when substring(u.unitcompleted, 1,2) = '06' then 0 end) '6AM',

    count(case when substring(u.unitcompleted, 1,2) = '07' then 0 end) '7AM',

    count(case when substring(u.unitcompleted, 1,2) = '08' then 0 end) '8AM',

    count(case when substring(u.unitcompleted, 1,2) = '09' then 0 end) '9AM',

    count(case when substring(u.unitcompleted, 1,2) = '10' then 0 end) '10AM',

    count(case when substring(u.unitcompleted, 1,2) = '11' then 0 end) '11AM',

    count(case when substring(u.unitcompleted, 1,2) = '12' then 0 end) '12PM',

    count(case when substring(u.unitcompleted, 1,2) = '01' then 0 end) '1PM',

    count(case when substring(u.unitcompleted, 1,2) = '02' then 0 end) '2PM',

    count(case when substring(u.unitcompleted, 1,2) = '03' then 0 end) '3PM',

    count(case when substring(u.unitcompleted, 1,2) = '04' then 0 end) '4PM'

    from completedUnit u

    join assignworkorder b on u.workorder = b.workorder

    where MONTH( u.dateentered ) = '6' and year(u.dateentered) = '2014'

    GROUP BY b.model

    ORDER BY b.model

    This works to get the results. I realized the data type is varchar with time as a string and not data type timestamp.

    Glad you figured it out. I would highly recommend you follow my previous suggestion about your where clause. It will help the performance of your query quite a bit.

    _______________________________________________________________

    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/