如何编辑此Access SQL代码

时间:2016-05-31 21:11:24

标签: sql sql-server ms-access database-migration

我是这个领域的新手,所以如果你能帮助我,我将不胜感激。我在我的Access中有这个SQL代码,现在我需要在Microsoft SQL服务器管理工​​作室中使用相同的代码。所以我需要编辑一些但不知道的内容和方法。

SELECT Server.Outlook, Server.Region, 
  Server.Country, Server.Territory, Server.Branch, 
  Server.Tier, Server.Division, Server.Type, 
  Server.Year, Server.sMonth, 
  IIf([Data]="Extra Trips",[Qty],0) AS [Extra Trips], 
  IIf([Data]="Hours",[Qty],0) AS Hours, 
  IIf([Data]="Predict",[Qty],0) AS Predict, 
  IIf([Data]="Reduc",[Qty],0) AS Reduc, 
  IIf([Data]="Rev",[Qty],0) AS Rev, 
  IIf([Data]="Service Req",[Qty],0) AS [Service Req],    
  IIf([Data]="TCUP",[Qty],0) AS TCUP, 
  IIf([Data]="Total Kills",[Qty],0) AS [Total Kills], 
  IIf([Data]="Work Ord",[Qty],0) AS [Work Ord], 
  IIf([Data]="FTE",[Qty],0) AS FTE 
INTO Server_FINAL
FROM Server;

1 个答案:

答案 0 :(得分:2)

您的IIF语句可能需要转换为case语句。例如:

CASE WHEN [DATA]='Extra Trips' THEN Qty ELSE 0 END as [Extra Trips],

注意:根据您的特定设置,SQL Server可能使用带引号的标识符而不是括号。因此,如果它不喜欢[DATA][Extra Trips],请尝试改为"DATA""Extra Trips"