PIVOT sql with fixed value...

User avatar
sal21
PlatinumLounger
Posts: 4357
Joined: 26 Apr 2010, 17:36

PIVOT sql with fixed value...

Post by sal21 »

Code: Select all

SQL = "TRANSFORM ecc...." & _
        " SELECT ecc" & _
        " FROM ecc..." & _
        " Where ecc...'" & _
        " GROUP BY ecc..." & _
        " PIVOT VER.ANNO"
instead to use VER.ANNO, possible to use a string ('2012','2013',...'2017')...

User avatar
HansV
Administrator
Posts: 78512
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: PIVOT sql with fixed value...

Post by HansV »

You can use

Code: Select all

SQL = "TRANSFORM ecc..." & _
        " SELECT ecc..." & _
        " FROM ecc..." & _
        " WHERE ecc...'" & _
        " GROUP BY ecc..." & _
        " PIVOT VER.ANNO IN ('2012','2013','2014','2015','2016','2017')"
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4357
Joined: 26 Apr 2010, 17:36

Re: PIVOT sql with fixed value...

Post by sal21 »

HansV wrote:You can use

Code: Select all

SQL = "TRANSFORM ecc..." & _
        " SELECT ecc..." & _
        " FROM ecc..." & _
        " WHERE ecc...'" & _
        " GROUP BY ecc..." & _
        " PIVOT VER.ANNO IN ('2012','2013','2014','2015','2016','2017')"
hummm...

but really my prob is to rapresent in other case although not all records have values for years...

User avatar
HansV
Administrator
Posts: 78512
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: PIVOT sql with fixed value...

Post by HansV »

If you use

PIVOT VER.ANNO IN ('2012','2013','2014','2015','2016','2017')

the query will display a column for 2012, 2013, ..., 2017, whether there are records for all those years or not.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4357
Joined: 26 Apr 2010, 17:36

Re: PIVOT sql with fixed value...

Post by sal21 »

HansV wrote:If you use

PIVOT VER.ANNO IN ('2012','2013','2014','2015','2016','2017')

the query will display a column for 2012, 2013, ..., 2017, whether there are records for all those years or not.
sorry for delay...
The tips is perfect!
Tks.