谁能告诉我此查询中的错误 [英] Can anyone tell me error in this query

查看:73
本文介绍了谁能告诉我此查询中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我此查询中的错误吗?


Can anyone tell me error in this query


SELECT  TxnAttributesID,TxnAttributesName,AccountabilityTypeID,TxnAttributesValue,[DAY],[GRAVE],[SWING],
CreatedDate,ModifiedDate
    FROM    ( SELECT   t1.TxnAttributesID,t1.TxnAttributesName,t1.AccountabilityTypeID,t2.TxnAttributesValue,t3.ShiftTypeID,
    t3.ShiftTypeName,t2.CreatedDate,t2.ModifiedDate
         from Code.tblTxnAttributes as t1 inner join
         App.tblDailyRevDetail as t2 on t1.TxnAttributesID = t2.TxnAttributesID
         inner join App.tblShiftType as t3 on t2.ShiftTypeID = t3.ShiftTypeID) as P

             PIVOT (SUM(cast(TxnAttributesValue as int)) FOR ShiftTypeName IN ([DAY],[GRAVE],[SWING])) AS pvt
    ORDER BY CreatedDate




给予消息102,第15级,状态1,第9行
''(''附近的语法不正确.


但是我已经检查并且所有窗口都已正确关闭




Its giving Msg 102, Level 15, State 1, Line 9
Incorrect syntax near ''(''.


but i have checked and all are closed properly

推荐答案

问题是我也在选择列表中选择了要为其创建数据透视表的字段.我将其从列表中删除并得到了答案.
The problem was that i was selecting the field also in select list for which i was creating pivot . I removed it from the list and got my answer.


我不确定,但是根据PIVOT Syntax ,此处给出了
http://msdn.microsoft.com/en-us/library/ms177410 (v = sql.90).aspx [ ^ ]在第一个Select语句中,非透视列应首先出现,然后再指定透视列.

在此问题中,非枢轴式列
I am not sure but as per the Syntax of PIVOT given here
http://msdn.microsoft.com/en-us/library/ms177410(v=sql.90).aspx[^] in the first Select statement the non pivoted columns shall come first and then the pivoted columns shall be specified.

Here in the question the non pivoted columns
CreatedDate,ModifiedDate

在透视列之后给出

are given after the pivoted columns

[DAY],[GRAVE],[SWING]


将未旋转的列移到旋转的列之前,然后尝试.


Shift the non pivoted columns before pivoted columns and try.


这篇关于谁能告诉我此查询中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆