有关查询的错误

2020-09-02 23:27发布

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


尊敬的专家,

执行此查询时出现以下错误

'1)。 [Microsoft] [用于SQL Server的ODBC驱动程序13] [SQL Server]列名或提供的值数与表定义不匹配。 2)。 [Microsoft] [用于SQL Server的ODBC驱动程序13] [SQL Server]无法准备声明"空白协议"(OOAT)。'

请在此查询中解决错误,它对我来说很紧急。

/*从[DBO]中选择。[JDT1] T1 */声明@ refdt1日期设置@ refdt1 =/*从jdt1 t0中选择1,其中t1.RefDate */'[%1]'/*从[DBO中选择 ]。[JDT1] T1 */声明@ refdt2日期集@ refdt2 =/*从jdt1 t0中选择1,其中t1.RefDate */'[%2]'/* @mthend_XX变量返回从[%1]开始的eom日期*/----------声明@ mthend_00日期/* OpBal_00 */设置@ mthend_00 =(DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,@ refdt1)+0,0) ))----------声明@ mthend_01日期/*第一个月末*/设置@ mthend_01 =(DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,@ refdt1)+ 1,0)))----------声明@ mthend_02日期集@ mthend_02 =(DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,@ refdt1)+2,0) ))----------声明@ mthend_03日期集@ mthend_03 =(DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,@ refdt1)+3,0)))- --------声明@ mthend_04日期集@ mthend_04 =(DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,@ refdt1)+4,0)))------ ----声明@ mthend_05日期设置为@ mthend_05 =(DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,@ refdt1)+5,0)))- --------声明@ mthend_06日期设置为@ mthend_06 =(DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,@ refdt1)+6,0)))------ ----声明@ mthend_07日期集@ mthend_07 =(DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,@ refdt1)+7,0)))---------- 声明@ mthend_08日期设置@ mthend_08 =(DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,@ refdt1)+8,0)))----------声明@ mthend_09日期 设置@ mthend_09 =(DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,@ refdt1)+9,0)))----------声明@ mthend_10日期set @ mthend_10 = (DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,@ refdt1)+10,0)))----------声明@ mthend_11日期设置@ mthend_11 =(DATEADD(s ,-1,DATEADD(mm,DATEDIFF(m,0,@ refdt1)+11,0)))----------声明@ mthend_12日期集@ mthend_12 =(DATEADD(s,-1, DATEADD(mm,DATEDIFF(m,0,@ refdt1)+12,0)))创建表#ColNamesP(Col_ID1 int,Col_Name varchar(max))/*该表包含列标题:Jan-11,Feb-11, 等等... */插入#ColNamesP值(MONTH(@ refdt1)+0,左(DATENAME(mm,(DATEADD(mm,0,@ refdt1))),3)+'-'+ RI GHT(CAST(YEAR(DATEADD(mm,0,@ refdt1))as varchar),2)),(MONTH(@ refdt1)+1,LEFT(DATENAME(mm,(DATEADD(mm,1,@ refdt1))) ),3)+'-'+ RIGHT(CAST(YEAR(DATEADD(mm,1,@ refdt1))as varchar),2)),(MONTH(@ refdt1)+2,LEFT(DATENAME(mm,(DATEADD (mm,2,@ refdt1))),3)+'-'+ RIGHT(CAST(YEAR(DATEADD(mm,2,@ refdt1))as varchar),2)),(MONTH(@ refdt1)+3 ,LEFT(DATENAME(mm,(DATEADD(mm,3,@ refdt1))),3)+'-'+ RIGHT(CAST(YEAR(DATEADD(mm,3,@ refdt1))如varchar),2)) ,(MONTH(@ refdt1)+4,左(DATENAME(mm,(DATEADD(mm,4,@ refdt1))),3)+'-'+右(CAST(YEAR(DATEADD(mm,4,@ refdt1 ))as varchar),2)),(MONTH(@ refdt1)+5,LEFT(DATENAME(mm,(DATEADD(mm,5,@ refdt1))),3)+'-'+ RIGHT(CAST(YEAR (DATEADD(mm,5,@ refdt1))作为varchar),2)),(MONTH(@ refdt1)+6,LEFT(DATENAME(mm,(DATEADD(mm,6,@ refdt1))),3)+ '-'+ RIGHT(CAST(YEAR(DATEADD(mm,6,@ refdt1))为varchar),2)),(MONTH(@ refdt1)+7,LEFT(DATENAME(mm,(DATEADD(mm,7, @ refdt1))),3)+'-'+右(CAST(YEAR(DATEADD(mm,7,@ refdt1))为varchar),2)),(MONTH(@ refdt1)+8,LE FT(DATENAME(mm,(DATEADD(mm,8,@ refdt1))),3)+'-'+ RIGHT(CAST(YEAR(DATEADD(mm,8,@ refdt1))如varchar),2)), (MONTH(@ refdt1)+9,左(DATENAME(mm,(DATEADD(mm,9,@ refdt1))),3)+'-'+右(CAST(YEAR(DATEADD(mm,9,@ refdt1)) )作为varchar),2)),(MONTH(@ refdt1)+10,左(DATENAME(mm,(DATEADD(mm,10,@ refdt1))),3)+'-'+ RIGHT(CAST(YEAR( DATEADD(mm,10,@ refdt1))作为varchar),2)),(MONTH(@ refdt1)+11,LEFT(DATENAME(mm,(DATEADD(mm,11,@ refdt1))),3)+' -'+右(CAST(YEAR(DATEADD(mm,11,@ refdt1))为varchar),2))创建表#FinalP(Col_ID2 varchar(max),AcCode varchar(max),AcGroup varchar(max),AcName varchar(max),Debit Numeric(18,6))插入到#FinalP SELECT LEFT(日期名(mm,T1.RefDate),3)+'-'+ RIGHT(CAST(年(T1.RefDate)为varchar), 2),T1.Account为'AcCode',T2.AcctName为'AcName',SUM(T1.Debit)为'Debit'FROM [dbo]。[测试] t0对T1进行内部连接jdt1t1。[TransId] = t0。 [TransId]左加入OACT t2在T2.AcctCode = T1.Account WHERE t1。[Project] ='CISL/OM092'和t1.shortName <>'SI00004'和t1.transtype在('30','18')和T1.RefDate> = @ refdt1和T1.RefDate <= @ refdt2按t1分组.RefDate,T1.Account,T2.AcctName DECLARE @ StringOfColsP nvarchar(2000)选择@StringOfColsP = COALESCE(@StringOfColsP +',['+ Col_Name +']','['+ Col_Name +']','['+ Col_Name +']','['+ Col_Name +']')FROM #ColNamesP按Col_ID1排序DECLARE @queryP nvarchar(4000)SET @queryP = N'SELECT AcCode作为[Account],借方作为[Debit],AcName作为[AcctName],'+ @StringOfColsP +'FROM -----------子查询---------(选择t2.Col_ID2为[Col_ID2],t2.AcCode,t2.AcName,t2.Debit from #FinalP t2)p- ---------数据透视PL ------------ PIVOT([[Col_ID2] IN('+ @ StringOfColsP +')的总和([借项]))AS pvt'EXECUTE(@ queryP)DROP TABLE #ColNamesP,#FinalP

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


尊敬的专家,

执行此查询时出现以下错误

'1)。 [Microsoft] [用于SQL Server的ODBC驱动程序13] [SQL Server]列名或提供的值数与表定义不匹配。 2)。 [Microsoft] [用于SQL Server的ODBC驱动程序13] [SQL Server]无法准备声明"空白协议"(OOAT)。'

请在此查询中解决错误,它对我来说很紧急。

/*从[DBO]中选择。[JDT1] T1 */声明@ refdt1日期设置@ refdt1 =/*从jdt1 t0中选择1,其中t1.RefDate */'[%1]'/*从[DBO中选择 ]。[JDT1] T1 */声明@ refdt2日期集@ refdt2 =/*从jdt1 t0中选择1,其中t1.RefDate */'[%2]'/* @mthend_XX变量返回从[%1]开始的eom日期*/----------声明@ mthend_00日期/* OpBal_00 */设置@ mthend_00 =(DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,@ refdt1)+0,0) ))----------声明@ mthend_01日期/*第一个月末*/设置@ mthend_01 =(DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,@ refdt1)+ 1,0)))----------声明@ mthend_02日期集@ mthend_02 =(DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,@ refdt1)+2,0) ))----------声明@ mthend_03日期集@ mthend_03 =(DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,@ refdt1)+3,0)))- --------声明@ mthend_04日期集@ mthend_04 =(DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,@ refdt1)+4,0)))------ ----声明@ mthend_05日期设置为@ mthend_05 =(DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,@ refdt1)+5,0)))- --------声明@ mthend_06日期设置为@ mthend_06 =(DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,@ refdt1)+6,0)))------ ----声明@ mthend_07日期集@ mthend_07 =(DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,@ refdt1)+7,0)))---------- 声明@ mthend_08日期设置@ mthend_08 =(DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,@ refdt1)+8,0)))----------声明@ mthend_09日期 设置@ mthend_09 =(DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,@ refdt1)+9,0)))----------声明@ mthend_10日期set @ mthend_10 = (DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,@ refdt1)+10,0)))----------声明@ mthend_11日期设置@ mthend_11 =(DATEADD(s ,-1,DATEADD(mm,DATEDIFF(m,0,@ refdt1)+11,0)))----------声明@ mthend_12日期集@ mthend_12 =(DATEADD(s,-1, DATEADD(mm,DATEDIFF(m,0,@ refdt1)+12,0)))创建表#ColNamesP(Col_ID1 int,Col_Name varchar(max))/*该表包含列标题:Jan-11,Feb-11, 等等... */插入#ColNamesP值(MONTH(@ refdt1)+0,左(DATENAME(mm,(DATEADD(mm,0,@ refdt1))),3)+'-'+ RI GHT(CAST(YEAR(DATEADD(mm,0,@ refdt1))as varchar),2)),(MONTH(@ refdt1)+1,LEFT(DATENAME(mm,(DATEADD(mm,1,@ refdt1))) ),3)+'-'+ RIGHT(CAST(YEAR(DATEADD(mm,1,@ refdt1))as varchar),2)),(MONTH(@ refdt1)+2,LEFT(DATENAME(mm,(DATEADD (mm,2,@ refdt1))),3)+'-'+ RIGHT(CAST(YEAR(DATEADD(mm,2,@ refdt1))as varchar),2)),(MONTH(@ refdt1)+3 ,LEFT(DATENAME(mm,(DATEADD(mm,3,@ refdt1))),3)+'-'+ RIGHT(CAST(YEAR(DATEADD(mm,3,@ refdt1))如varchar),2)) ,(MONTH(@ refdt1)+4,左(DATENAME(mm,(DATEADD(mm,4,@ refdt1))),3)+'-'+右(CAST(YEAR(DATEADD(mm,4,@ refdt1 ))as varchar),2)),(MONTH(@ refdt1)+5,LEFT(DATENAME(mm,(DATEADD(mm,5,@ refdt1))),3)+'-'+ RIGHT(CAST(YEAR (DATEADD(mm,5,@ refdt1))作为varchar),2)),(MONTH(@ refdt1)+6,LEFT(DATENAME(mm,(DATEADD(mm,6,@ refdt1))),3)+ '-'+ RIGHT(CAST(YEAR(DATEADD(mm,6,@ refdt1))为varchar),2)),(MONTH(@ refdt1)+7,LEFT(DATENAME(mm,(DATEADD(mm,7, @ refdt1))),3)+'-'+右(CAST(YEAR(DATEADD(mm,7,@ refdt1))为varchar),2)),(MONTH(@ refdt1)+8,LE FT(DATENAME(mm,(DATEADD(mm,8,@ refdt1))),3)+'-'+ RIGHT(CAST(YEAR(DATEADD(mm,8,@ refdt1))如varchar),2)), (MONTH(@ refdt1)+9,左(DATENAME(mm,(DATEADD(mm,9,@ refdt1))),3)+'-'+右(CAST(YEAR(DATEADD(mm,9,@ refdt1)) )作为varchar),2)),(MONTH(@ refdt1)+10,左(DATENAME(mm,(DATEADD(mm,10,@ refdt1))),3)+'-'+ RIGHT(CAST(YEAR( DATEADD(mm,10,@ refdt1))作为varchar),2)),(MONTH(@ refdt1)+11,LEFT(DATENAME(mm,(DATEADD(mm,11,@ refdt1))),3)+' -'+右(CAST(YEAR(DATEADD(mm,11,@ refdt1))为varchar),2))创建表#FinalP(Col_ID2 varchar(max),AcCode varchar(max),AcGroup varchar(max),AcName varchar(max),Debit Numeric(18,6))插入到#FinalP SELECT LEFT(日期名(mm,T1.RefDate),3)+'-'+ RIGHT(CAST(年(T1.RefDate)为varchar), 2),T1.Account为'AcCode',T2.AcctName为'AcName',SUM(T1.Debit)为'Debit'FROM [dbo]。[测试] t0对T1进行内部连接jdt1t1。[TransId] = t0。 [TransId]左加入OACT t2在T2.AcctCode = T1.Account WHERE t1。[Project] ='CISL/OM092'和t1.shortName <>'SI00004'和t1.transtype在('30','18')和T1.RefDate> = @ refdt1和T1.RefDate <= @ refdt2按t1分组.RefDate,T1.Account,T2.AcctName DECLARE @ StringOfColsP nvarchar(2000)选择@StringOfColsP = COALESCE(@StringOfColsP +',['+ Col_Name +']','['+ Col_Name +']','['+ Col_Name +']','['+ Col_Name +']')FROM #ColNamesP按Col_ID1排序DECLARE @queryP nvarchar(4000)SET @queryP = N'SELECT AcCode作为[Account],借方作为[Debit],AcName作为[AcctName],'+ @StringOfColsP +'FROM -----------子查询---------(选择t2.Col_ID2为[Col_ID2],t2.AcCode,t2.AcName,t2.Debit from #FinalP t2)p- ---------数据透视PL ------------ PIVOT([[Col_ID2] IN('+ @ StringOfColsP +')的总和([借项]))AS pvt'EXECUTE(@ queryP)DROP TABLE #ColNamesP,#FinalP

付费偷看设置
发送
1条回答
spaceman01
1楼-- · 2020-09-02 23:55

亲爱的

我建议将这个查询分为几个小部分,然后测试是什么导致了此问题。 它的重要声明没有人能够知道哪个部分导致了错误。

一周热门 更多>