多部分标识符无法与链接服务器

时间:2015-09-21 07:45:49

标签: sql-server sql-server-2008 tsql

我试图在2008 R2中运行以下SQL查询,但在where子句中添加以下行时会出现以下错误;否则查询会完美执行。

SL.Location_strCode IN ('0005') AND

错误:

  

Msg 8180,Level 16,State 1,Line 1

     

无法准备声明。

     

Msg 4104,Level 16,State 1,Line 1

     

多部分标识符" Tbl1007.UserG_strDesc"无法受约束。

     

Msg 4104,Level 16,State 1,Line 1

     

多部分标识符" Tbl1005.User_strLastName"无法受约束。

     

Msg 4104,Level 16,State 1,Line 1

     

多部分标识符" Tbl1005.User_strFirstName"无法受约束。

     

Msg 207,Level 16,State 1,Line 1

     

列名称无效' Col1276'。

     

Msg 207,Level 16,State 1,Line 1

     

列名称无效' Col1275'。

     

Msg 4104,Level 16,State 1,Line 1

     

多部分标识符" Tbl1001.TransI_curFullPrice"无法受约束。

     

Msg 4104,Level 16,State 1,Line 1

     

多部分标识符" Tbl1001.TransI_decActualNoOfItems"无法受约束。

     

Msg 4104,Level 16,State 1,Line 1

     

多部分标识符" Tbl1001.DiscountR_strRptCode"无法受约束。

     

Msg 4104,Level 16,State 1,Line 1

     

多部分标识符" Tbl1001.TransI_curDiscount"无法受约束。

     

Msg 4104,Level 16,State 1,Line 1

     

多部分标识符" Tbl1001.Workstation_strCode"无法受约束。

     

Msg 4104,Level 16,State 1,Line 1

     

多部分标识符" Tbl1001.User_intUserNo"无法受约束。

     

Msg 4104,Level 16,State 1,Line 1

     

多部分标识符" Tbl1001.TransI_curSTaxEach"无法受约束。

     

Msg 4104,Level 16,State 1,Line 1

     

多部分标识符" Tbl1001.TransI_curValueEach"无法受约束。

     

Msg 4104,Level 16,State 1,Line 1

     

多部分标识符" Tbl1001.Item_strItemId"无法受约束。

查询:

SELECT
    TransI.Item_strItemId,
    POSS.POSS_dtmBusinessDate AS 'BusinessDate', 
    CONVERT(VARCHAR(8),POSS.POSS_dtmBusinessDate, 112)AS 'BusinessDateISO', 
    DATENAME(yy,POSS.POSS_dtmBusinessDate)AS 'BusinessDateYear',
    'Q' + DATENAME(qq,POSS.POSS_dtmBusinessDate) AS 'BusinessDateQuarter',
    DATENAME(mm,POSS.POSS_dtmBusinessDate) AS 'BusinessDateMonth',
    DATENAME(dw,POSS.POSS_dtmBusinessDate) AS 'BusinessDateDay', 
    ISNULL(UPPER(POSS.WGroup_strCode), '') AS 'WorkstationGroupID',
    ISNULL(WG.WGroup_strDescription, '') AS 'WorkstationGroupDesc',
    ISNULL(UPPER(TransI.Workstation_strCode), '') AS 'WorkstationID',
    LOWER(UG.UserG_strDesc) AS 'UserGroup',
    TransI.User_intUserNo AS 'UserNo',
    U.User_strFirstName AS 'UserFirstName',
    U.User_strLastName AS 'UserLastName',
    U.User_strFirstName + ' ' + User_strLastName AS 'UserFullName',
    '1.0' AS 'ReportGroup1Code',
    'Sales' AS 'ReportGroup1Desc',
    CASE 
        WHEN LOWER(IC.Class_strDescription) LIKE '%epass%' THEN '7.0'
        WHEN LOWER(IC.Class_strDescription) LIKE '%car%park%' THEN '6.0'
        WHEN LOWER(IC.Class_strDescription) LIKE '%magazine%' THEN '5.0'
        WHEN LOWER(IC.Class_strDescription) LIKE '%booking%fee%' THEN '4.0'
        WHEN LOWER(IC.Class_strDescription) LIKE '%voucher%' THEN '3.0'
        ELSE
        '2.0'
    END AS 'ReportGroup2Code',
    CASE 
        WHEN LOWER(IC.Class_strDescription) LIKE '%epass%' THEN 'EPass'
        WHEN LOWER(IC.Class_strDescription) LIKE '%car%park%' THEN 'Car Park Coupons'
        WHEN LOWER(IC.Class_strDescription) LIKE '%magazine%' THEN 'Magazines'
        WHEN LOWER(IC.Class_strDescription) LIKE '%booking%fee%' THEN 'Booking Fees'
        WHEN LOWER(IC.Class_strDescription) LIKE '%voucher%' THEN 'Vouchers'
        ELSE
        'Concessions'
    END AS 'ReportGroup2Desc',
    CO.CinOperator_strCode AS 'DepartmentCode',
    CO.CinOperator_strName AS 'DepartmentDesc',
    'Sales' AS 'TransTypeCode', 
    'Sales' AS 'TransTypeDesc',
    TransI.DiscountR_strRptCode AS 'TransDiscountCode',
    TransI.DiscountR_strRptCode AS 'TransDiscountDesc',
    SUM(TransI.TransI_decActualNoOfItems) AS 'TransQuantity',
    SUM(TransI.TransI_curFullPrice * TransI.TransI_decActualNoOfItems) AS 'TransFullValue',
    SUM(TransI.TransI_curValueEach * TransI.TransI_decActualNoOfItems) AS 'TransValue', 
    SUM(TransI.TransI_curDiscount) AS 'TransDiscountValue',
    SUM(TransI.TransI_curSTaxEach * TransI.TransI_decActualNoOfItems) AS 'TransTaxValue'--,
    --@DutyManager
FROM 
TDMVISTA_CLUSTER.VISTA.dbo.tblTrans_Inventory TransI
INNER JOIN TDMVISTA_CLUSTER.VISTA.dbo.tblPOS_Sess POSS ON POSS.POSS_intPOSSessionNumber = TransI.TransI_lngPOSSessionID 
AND POSS.POSS_dtmBusinessDate = CONVERT(VARCHAR,GETDATE()-1,111)
INNER JOIN TDMVISTA_CLUSTER.VISTA.dbo.tblUser U ON U.User_intUserNo = TransI.User_intUserNo
INNER JOIN TDMVISTA_CLUSTER.VISTA.dbo.tblUser_Group UG ON UG.UserG_strCode = U.UserG_strCode
INNER JOIN TDMVISTA_CLUSTER.VISTA.dbo.tblStock_Location SL ON SL.Location_strCode = TransI.Location_strCode
INNER JOIN TDMVISTA_CLUSTER.VISTA.dbo.tblCinema_Operator CO ON CO.CinOperator_strCode = SL.CinOperator_strCode
INNER JOIN TDMVISTA_CLUSTER.VISTA.dbo.tblItem Item ON Item.Item_strItemId = TransI.Item_strItemId
INNER JOIN TDMVISTA_CLUSTER.VISTA.dbo.tblItem_Class IC ON IC.Class_strCode = Item.Class_strCode
LEFT OUTER JOIN TDMVISTA_CLUSTER.VISTA.dbo.tblWorkstation_Group WG ON WG.WGroup_strCode = POSS.WGroup_strCode 
WHERE
    POSS.POSS_dtmBusinessDate = CONVERT(VARCHAR,GETDATE()-1,111)
    AND TransI.TransI_strType = 'S' AND 
    TransI.TransI_strStatus <> 'W' AND
    TransI.Item_strItemId NOT IN ('9020','9021') AND

    -- below line is creating the error
    SL.Location_strCode IN ('0005') AND

    LOWER(IC.Class_strDescription) NOT LIKE '%voucher%'
    AND LOWER(IC.Class_strDescription) NOT LIKE '%booking%fee%'
    AND U.User_intUserNo > 0
    AND lower(WG.WGroup_strDescription) NOT LIKE ('%cross selling%')
GROUP BY
    POSS.POSS_dtmBusinessDate,
    POSS.WGroup_strCode,
    WG.WGroup_strDescription,
    TransI.Workstation_strCode,
    UG.UserG_strDesc,
    TransI.User_intUserNo,
    U.User_strFirstName,
    U.User_strLastName,
    CO.CinOperator_strCode,
    CO.CinOperator_strName, 
    CASE 
        WHEN LOWER(IC.Class_strDescription) LIKE '%epass%' THEN '7.0'
        WHEN LOWER(IC.Class_strDescription) LIKE '%car%park%' THEN '6.0'
        WHEN LOWER(IC.Class_strDescription) LIKE '%magazine%' THEN '5.0'
        WHEN LOWER(IC.Class_strDescription) LIKE '%booking%fee%' THEN '4.0'
        WHEN LOWER(IC.Class_strDescription) LIKE '%voucher%' THEN '3.0'
        ELSE
        '2.0'
    END,
    CASE 
        WHEN LOWER(IC.Class_strDescription) LIKE '%epass%' THEN 'EPass'
        WHEN LOWER(IC.Class_strDescription) LIKE '%car%park%' THEN 'Car Park Coupons'
        WHEN LOWER(IC.Class_strDescription) LIKE '%magazine%' THEN 'Magazines'
        WHEN LOWER(IC.Class_strDescription) LIKE '%booking%fee%' THEN 'Booking Fees'
        WHEN LOWER(IC.Class_strDescription) LIKE '%voucher%' THEN 'Vouchers'
        ELSE
        'Concessions'
    END,
    TransI.DiscountR_strRptCode,
    TransI.Item_strItemId

1 个答案:

答案 0 :(得分:0)

条件从

更改后
SL.Location_strCode IN ('0005') AND 

CAST(SL.Location_strCode AS VARCHAR(4)) IN ('0005') AND

查询工作正常。