Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2004
    Location
    Long Island
    Posts
    696

    Unanswered: PIVOT with Subquery

    Is it possible to create a pivot list, instead of hardcoding, without having to build it with dynamic sql ?
    ie:
    select * from (select Period, loan_id, mba_stat from lp_cq where loan_id = 'AaAaCz') a
    pivot (
    max(mba_stat) for period IN
    (select cast(period as varchar) from lp_cq where loan_id = 'AaAaCz')
    ) b
    instead of
    select * from (select Period, loan_id, mba_stat from lp_cq where loan_id = 'AaAaCz') a
    pivot (
    max(mba_stat) for period IN
    ([1], [2],..[200])
    ) b

  2. #2
    Join Date
    Jun 2004
    Location
    Long Island
    Posts
    696
    Built with Dynamic sql, took all of 10 minutes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •