2016-07-22 11 views
0

我正在使用SQL Server。我試圖進入一個別名字段,作爲一個佔位符(還沒有收到這個數據),我不斷收到錯誤。請看下圖。如何輸入別名並在此字段中輸入全部「」?

enter image description here

我不知道如何在SQL服務器中設置的,但在訪問它僅僅是這樣的:

enter image description here

任何想法如何,我可以使這項工作?

感謝所有。 下面是SQL腳本:

SELECT  dbo.Plan_ID_Mapping.[Level 3 Service], dbo.Plan_ID_Mapping.[PLAN ID], 
         dbo.All_Enteprise_NONProduction_and_Production_Hardware.Application_Systems_Software_ID_CI_ID AS CI_ID, 
         dbo.All_Enteprise_NONProduction_and_Production_Hardware.Application_Systems_Software_Name_CI_Name AS CI_Name, 
         dbo.All_Enteprise_NONProduction_and_Production_Hardware.Description_Product_Name, dbo.Service_Taxonomy.[Critical Y/N], 
         dbo.Service_Taxonomy.[Criticality Rationale], dbo.qry_BE.BE, dbo.qry_BE.Street, dbo.qry_BE.City, dbo.qry_BE.ST, dbo.qry_BE.Zip, dbo.qry_BE.Country, 
         dbo.qry_BE.O_L, dbo.qry_BE.ENTITY, dbo.qry_BE.Comp_Code 
FROM   dbo.Plan_ID_Mapping INNER JOIN 
         dbo.All_Enteprise_NONProduction_and_Production_Hardware ON 
         dbo.Plan_ID_Mapping.[PLAN ID] = dbo.All_Enteprise_NONProduction_and_Production_Hardware.Plan_Id INNER JOIN 
         dbo.LocationWorkSpaceByPlanWithAllIn ON 
         dbo.All_Enteprise_NONProduction_and_Production_Hardware.Plan_Id = dbo.LocationWorkSpaceByPlanWithAllIn.Plan_Id INNER JOIN 
         dbo.qry_BE ON dbo.LocationWorkSpaceByPlanWithAllIn.Location_ID = dbo.qry_BE.BE INNER JOIN 
         dbo.Service_Taxonomy ON dbo.Plan_ID_Mapping.[Level 3 Service] = dbo.Service_Taxonomy.[Level 3] 
GROUP BY dbo.Plan_ID_Mapping.[Level 3 Service], dbo.All_Enteprise_NONProduction_and_Production_Hardware.Application_Systems_Software_ID_CI_ID, 
         dbo.All_Enteprise_NONProduction_and_Production_Hardware.Application_Systems_Software_Name_CI_Name, dbo.Plan_ID_Mapping.[PLAN ID], 
         dbo.All_Enteprise_NONProduction_and_Production_Hardware.Description_Product_Name, dbo.Service_Taxonomy.[Critical Y/N], 
         dbo.Service_Taxonomy.[Criticality Rationale], dbo.qry_BE.BE, dbo.qry_BE.Street, dbo.qry_BE.City, dbo.qry_BE.ST, dbo.qry_BE.Zip, dbo.qry_BE.Country, 
         dbo.qry_BE.O_L, dbo.qry_BE.ENTITY, dbo.qry_BE.Comp_Code 
+0

我們需要看到你的代碼。你的分組是不正確的。 – scsimon

+0

感謝您的代碼。上面的屏幕截圖中的PACKAGE_ID是什麼?它不包含在你的SQL腳本中 – scsimon

回答

1

快速解答: 取消選中GROUP BYPACKAGE_ID

說明

看起來PACKAGE_ID是要創建的別名列。如果哪裏沒有什麼東西,你就不能對它進行分組。爲了清晰起見,我使用表別名重寫了下面的查詢,並評論了它的真實外觀。正在發生的事情是,因爲你不具備任何PACKAGE_ID SQL語句字面上將反映:

SELECT NULL AS PACKAGE_ID

你的錯誤就在於試圖小組在NULLLITERAL。你不能在文字上分組。例如,下面的查詢將不起作用,因爲我們試圖在2007年文字上進行分組。爲了使其工作,我們必須從分組中刪除2007年。

SELECT 
    COLUMN1, 
    COLUMN2, 
    2007 
FROM 
    TABLE1 
GROUP BY 
    COLUMN1, 
    COLUMN2, 
    2007 

代碼

SELECT 
    map.[Level 3 Service], 
    map.[PLAN ID], 
    eh.Application_Systems_Software_ID_CI_ID AS CI_ID, 
    eh.Application_Systems_Software_Name_CI_Name AS CI_Name, 
    eh.Description_Product_Name, 
    tax.[Critical Y/N], 
    tax.[Criticality Rationale], 
    qry.BE, 
    qry.Street, 
    qry.City, 
    qry.ST, 
    qry.Zip, 
    qry.Country, 
    qry.O_L, 
    qry.ENTITY, 
    qry.Comp_Code, 
    NULL as PACKAGE_ID   --this is your blank alias field you created 
FROM 
    dbo.Plan_ID_Mapping map 
INNER JOIN 
    dbo.All_Enteprise_NONProduction_and_Production_Hardware eh ON 
    map.[PLAN ID] = eh.Plan_Id 
INNER JOIN 
    dbo.LocationWorkSpaceByPlanWithAllIn loc ON 
    eh.Plan_Id = loc.Plan_Id 
INNER JOIN 
    dbo.qry_BE qry ON 
    loc.Location_ID =qry.BE 
INNER JOIN 
    dbo.Service_Taxonomy tax ON 
    map.[Level 3 Service] = tax.[Level 3] 
GROUP BY 
    map.[Level 3 Service], 
    eh.Application_Systems_Software_ID_CI_ID, 
    eh.Application_Systems_Software_Name_CI_Name, 
    map.[PLAN ID], 
    eh.Description_Product_Name, 
    tax.[Critical Y/N], 
    tax.[Criticality Rationale], 
    qry.BE, 
    qry.Street, 
    qry.City, 
    qry.ST, 
    qry.Zip, 
    qry.Country, 
    qry.O_L, 
    qry.ENTITY, 
    qry.Comp_Code, 
    NULL     --This is your query trying to group on the blank field 
相關問題