Column Matching.

  • Hi All, trying to get my head around this one and failing somewhat! Any help would be much appreciated. I'm trying to retrieve value from a call counts table based on service levels in a threshold table based on join using ReportQueue.

    From the query below I'm trying to retrieve values 135 (Finance) and 210 (Marketing). This is based on a Finance service level of 60 and therefore relating to Threshold 6 and Marketing service level of 30 and so relating to Threshold 3.

    Any ideas greatly received!

    Thanks, Gary

    DROP TABLE #Thresholds

    DROP TABLE #CallCounts

    CREATE TABLE #Thresholds

    (

    CallQueue VARCHAR(20)

    ,ReportQueue VARCHAR(10)

    ,ServiceLevel INT

    ,Threshold1 INT

    ,Threshold2 INT

    ,Threshold3 INT

    ,Threshold4 INT

    ,Threshold5 INT

    ,Threshold6 INT

    )

    INSERT #Thresholds VALUES ('Finance', 'P200', 60, 10, 20, 30, 40, 50, 60)

    INSERT #Thresholds VALUES ('Marketing', 'P200', 30, 10, 20, 30, 40, 50, 60)

    CREATE TABLE #CallCounts

    (

    CallQueue VARCHAR(20)

    ,ReportQueue VARCHAR(10)

    ,Segment1 INT

    ,Segment2 INT

    ,Segment3 INT

    ,Segment4 INT

    ,Segment5 INT

    ,Segment6 INT

    )

    INSERT #CallCounts VALUES ('Finance', 'P200', 25, 52, 87, 99, 120, 135)

    INSERT #CallCounts VALUES ('Marketing', 'P200', 50, 123, 210, 268, 334, 393)

    SELECT * FROM #Thresholds

    SELECT * FROM #CallCounts

  • SELECT

    T.CallQueue, T.ReportQueue, T.ServiceLevel,

    CASE WHEN T.ServiceLevel = T.Threshold1 THEN C.Segment1

    WHEN T.ServiceLevel = T.Threshold2 THEN C.Segment2

    WHEN T.ServiceLevel = T.Threshold3 THEN C.Segment3

    WHEN T.ServiceLevel = T.Threshold4 THEN C.Segment4

    WHEN T.ServiceLevel = T.Threshold5 THEN C.Segment5

    WHEN T.ServiceLevel = T.Threshold6 THEN C.Segment6

    ELSE NULL END AS SegmentValue

    FROM #Thresholds T

    INNER JOIN #CallCounts C ON C.CallQueue = T.CallQueue AND C.ReportQueue = T.ReportQueue

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.

  • That's great, many thanks for your help!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply