MSLine chart using tabular query instead of unions

(2 posts) (2 voices)

Tags:

  1. dharkness, Member

    I have a query that generates a standard tabular report, and I'd like to chart that same data where the first column holds the x values and each other column holds a new series of y values.

    select sale_dt, item_count, sale from sales where . . .
    
    Day    Items    Sale
    --------------------
    Sun       15   $ 122
    Mon       11   $  95
    Tue        6   $  63
    Wed       18   $ 158
    Thu       13   $ 104
    Fri        8   $  92
    Sat       17   $ 147

    The day of the week is the x-axis and there are two lines: Items and Sale. Assume that each column will use the same y-axis scale. Is there a way to chart this easily?

    To create this type of chart I have been rewriting the query to select each series separately and combine them using unions.

    select 'Items', sale_dt, item_count from sales where . . .
    union
    select 'Sale', sale_dt, sale from sales where . . .

    Is there a way to avoid this?

  2. myDBR Team, Key Master

    If you are using SQL server, you can use CTE to define your query as basis for the union statement. Other than that, the union is way to go.

    --
    myDBR Team


Reply

You must log in to post.