Home Forums SQL Server 2008 T-SQL (SS2K8) Query seems to be constrained by single core CPU in multiple core server - any suggestions? RE: Query seems to be constrained by single core CPU in multiple core server - any suggestions?

  • Your query doesn't look very logical, especially in its select list part as it doesn't correspond to order by.

    Would be beneficial if you could post some test data (in a form of INSERT statements).

    For now you can try the following query, which does the same job without any joins.

    SELECT

    a.CompanyIdentifier

    ,COALESCE(MAX(CASE WHEN a.FieldIDNumber = 1 THEN a.Data ELSE NULL END)

    ,MAX(CASE WHEN a.FieldIDNumber = 2 THEN a.Data ELSE NULL END))

    ,COALESCE(MAX(CASE WHEN a.FieldIDNumber = 3 THEN a.Data ELSE NULL END)

    ,MAX(CASE WHEN a.FieldIDNumber = 4 THEN a.Data ELSE NULL END))

    ,MAX(CASE WHEN a.FieldIDNumber = 5 THEN a.Data ELSE NULL END) AS Data

    FROM SourceTable a

    WHERE LEFT(a.CompanyIdentifier, 5) != 'EXCLU'

    AND a.IndicatorRecordContainsAlphanumericNoteRatherThanData = ''

    GROUP BY a.CompanyIdentifier

    ORDER BY a.CompanyIdentifier

    If the record with FieldIDNumber = 1 and not "EXCLU" exists for every CompanyIdentifier, the above query should produce the same results (given that only one record per CompanyIdentifier, FieldIDNumber may exist).

    Also, you don't use PKColumn1NotPartOfQuery columns. What are they about?

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]