Filter Pivot Table

  • Hi

    I have below query & i want to filter data on 2 parameters

    Create PROC USP_Book

    (

    @ID VARCHAR(500),

    @sid VARCHAR(500)

    )

    AS

    BEGIN

    declare @cols as nvarchar(max)='';

    declare @query as nvarchar(max)='';

    select @cols = @cols + QUOTENAME(SName) + ',' from (Select distinct SName from View_Book) as tmp

    select @cols = substring(@cols,0,len(@cols))

    set @query = 'select Title, ' + @cols + ' from (select Title,Status,SName from tblData) x pivot

    ( Max(Status) for SName in (' + @cols + ')) piv ';

    execute (@query)

    Thanks

  • Normally, you do this in the UI... either PowerBI or Excel... unless you don't want to ever see that data.

    you can create a stored procedure and then use that as the source.

  • Ok... that's roughly the same query you've posted two other times.  It's not nice to cross post.  Stick with one thread on something like this.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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