# PIVOT queries in SQL - works in FDConnection but NOT in FDQuery - why?

**URL:** <https://community.cdata.com/t/pivot-queries-in-sql-works-in-fdconnection-but-not-in-fdquery-why/370>\
**Category:** CData Drivers\
**Tags:** sql, question, driver, excel\
**Created:** [August 30, 2023, 7:13pm UTC](https://community.cdata.com/t/pivot-queries-in-sql-works-in-fdconnection-but-not-in-fdquery-why/370 "2023-08-30T19:13:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gator](https://avatars.discourse-cdn.com/v4/letter/g/ecccb3/32.png) [@Gator](https://community.cdata.com/u/Gator)\
**Post date:** [August 30, 2023, 7:13pm UTC](https://community.cdata.com/t/pivot-queries-in-sql-works-in-fdconnection-but-not-in-fdquery-why/370/1 "2023-08-30T19:13:02Z")

</div>

Here is a simple example of a query that works in FDConnection but not FDQuery.&nbsp; This was tested on the 30 row Excel table using the CDataExcel driver id.&nbsp; The first component returns a 30 row result set.&nbsp; The second component fails on “field 2023-01 not found in subquery ….”

select “Budgeted Items”, “2023-01”, “2023-02”, “2023-03”, “2023-04”, “2023-05”, “2023-06”, “2023-07”, “2023-08”, “2023-09”, “2023-10”, “2023-11”, “2023-12” &nbsp;  
from  
(  
&nbsp; select “Budgeted Items”, “MonthNo”, “Amount”&nbsp;  
&nbsp; from “BUDGETED”  
) as SourceTable  
PIVOT  
(  
&nbsp; sum(“Amount”)  
&nbsp; for  
&nbsp; “MonthNo” in (“2023-01”, “2023-02”, “2023-03”, “2023-04”, “2023-05”, “2023-06”, “2023-07”, “2023-08”, “2023-09”, “2023-10”, “2023-11”, “2023-12”)  
)

---

<div class="post-metadata">

**Author:** ![Luçjano\_Capo](https://sea3.discourse-cdn.com/cdata/user_avatar/community.cdata.com/lu%C3%A7jano_capo/32/1638_2.png) [@Luçjano\_Capo](https://community.cdata.com/u/Lu%C3%A7jano_Capo)\
**Post date:** [September 15, 2023, 10:12am UTC](https://community.cdata.com/t/pivot-queries-in-sql-works-in-fdconnection-but-not-in-fdquery-why/370/2 "2023-09-15T10:12:52Z")

</div>

Hi&nbsp; @Gator ,

Your case is currently being handled by our support team. A ticket has filed to the development team and they are working on a solution.

We will keep you posted.
