缺少对象或列名称或empty.empty别名

时间:2016-11-29 07:43:31

标签: sql-server

为什么这个错误??

SELECT ( CASE
           WHEN BalanceTransfer.mobile_operator_desc = 'Paypoint'
                AND money_transfer.MoneyTransfer = 'NCELL' THEN 'Paypoint'
           WHEN BalanceTransfer.mobile_operator_desc = 'Paypoint'
                AND money_transfer.MoneyTransfer = 'UTLP' THEN 'Paypointutl'
           WHEN BalanceTransfer.mobile_operator_desc = 'Paypoint'
                AND money_transfer.MoneyTransfer = 'SIMTV' THEN 'Paypointsimtv'
           ELSE BalanceTransfer.mobile_operator_desc
         END ),
       ISNULL(CONVERT(VARCHAR, DT_date, 101), '''') Txndate,
       COUNT(*)                                     txn,
       reseller_agent.reseller_id,
       reseller_agent.userName,
       SUM(ISNULL(selling_price, 0.00))             amount,
       SUM(ISNULL(amount, 0.00))                    facevalue
INTO   #tempRoutewise
FROM   BalanceTransfer WITH ( NOLOCK )
       JOIN dbo.money_transfer WITH (NOLOCK)
         ON BalanceTransfer.mobile_operator = money_transfer.Mobile_Operator
       LEFT OUTER JOIN reseller_agent WITH ( NOLOCK )
                    ON BalanceTransfer.Branch_Id = reseller_agent.reseller_id
WHERE  1 = 1
       AND Status <> 'confirming'
       AND BalanceTransfer.mobile_operator IN( 1, 2, 6, 14, 15 )
       AND ISNULL(money_transfer.IsUtility, 'n') = 'y'
       AND money_transfer.Mobile_Operator IS NOT NULL
GROUP  BY BalanceTransfer.mobile_operator_desc,
          money_transfer.MoneyTransfer,
          reseller_agent.reseller_id,
          reseller_agent.userName,
          ISNULL(CONVERT(VARCHAR, DT_date, 101), '''')

SELECT *
FROM   #tempRoutewise 

1 个答案:

答案 0 :(得分:0)

正如马丁在评论中指出的那样,你的第一栏没有名字。您正在尝试创建一个表。显然,该表中的所有列都必须有一个名称,名称是您选择的列的名称。如果您尝试:

SELECT  CASE
           WHEN BalanceTransfer.mobile_operator_desc = 'Paypoint'
                AND money_transfer.MoneyTransfer = 'NCELL' THEN 'Paypoint'
           WHEN BalanceTransfer.mobile_operator_desc = 'Paypoint'
                AND money_transfer.MoneyTransfer = 'UTLP' THEN 'Paypointutl'
           WHEN BalanceTransfer.mobile_operator_desc = 'Paypoint'
                AND money_transfer.MoneyTransfer = 'SIMTV' THEN 'Paypointsimtv'
           ELSE BalanceTransfer.mobile_operator_desc
         END AS mobile_operator_desc ,
       ISNULL(CONVERT(VARCHAR, DT_date, 101), '''') Txndate,
       COUNT(*)                                     txn,
       reseller_agent.reseller_id,
       reseller_agent.userName,
       SUM(ISNULL(selling_price, 0.00))             amount,
       SUM(ISNULL(amount, 0.00))                    facevalue

它应该有用。