• The queries you posted have some stuff missing.

    In all cases you don't need to get the left 2 characters and then use like '%%'. The left can't possibly return anymore than 2 characters. Those could be greatly simplified to

    LEFT (idDGIG, 2) in ('QM', 'QI', 'QO', 'QS')

    Here is a snippet from your first query to show you what I mean about stuff missing.

    SELECT

    LEFT (idDGIG, 2) AS idDGIG,

    COUNT(idDGIG) AS NUMBER

    FROM

    TABLE_LONG

    WHERE

    1

    AND (

    LEFT (idDGIG, 2) LIKE '%QM%'

    OR LEFT (idDGIG, 2) LIKE '%QI%'

    OR LEFT (idDGIG, 2) LIKE '%QO%'

    OR LEFT (idDGIG, 2) LIKE '%QS%'

    )

    AND DATE_START = DATE_ADD(CURDATE(), INTERVAL - 1 DAY)

    You have Where 1 and...

    this doesn't work.

    _______________________________________________________________

    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/