繁体   English   中英

将MS Access中的VBA代码转换为SQL Server

[英]Convert VBA code in MS Access to SQL server

下面的代码来自MS Access,我正在尝试将其转换并使其在SQL Server中工作。 我不知道如何转换包含IsNull的最后一行。 PS:LIS是驱动器的名称。 感谢任何可以给我提示的人。

SELECT DISTINCT [Molecular Pathology].[ID#], [Molecular Pathology].[Last Name], 
[Molecular Pathology].[First Name], [Molecular Pathology].Gender, 
[Molecular Pathology].[Date of Birth], [Molecular Tests].[Test Type], 
[Molecular Pathology].[Testing Gene], [Molecular Pathology].[Testing Exon], 
[Molecular Pathology].[Tested Mutation], [Molecular Pathology].[Testing Gene 2], 
[Molecular Pathology].[Testing Exon 2], [Molecular Pathology].[Tested Mutation 2], 
[Molecular Tests].[Test Name], [Molecular Pathology].[Result Reported],
[Molecular Pathology].[Date Received], [Molecular Pathology].[gp#]
FROM ([Molecular Pathology] 
LEFT JOIN [Molecular Select Tests] 
  ON [Molecular Pathology].ID = [Molecular Select Tests].ForKey) 
LEFT JOIN [Molecular Tests] 
  ON [Molecular Select Tests].Test = [Molecular Tests].[Test Name]
WHERE ((IsNull([Molecular Pathology].[LIS SignOut])<>False));

只有几个小问题,但是,通过适当使用表别名,可以极大地提高此查询的可读性。 请尝试以下重写:

SELECT DISTINCT 
  mp.[ID#],            mp.[Last Name],       mp.[First Name], 
  mp.Gender,           mp.[Date of Birth],   mt.[Test Type],       
  mp.[Testing Gene],   mp.[Testing Exon],    mp.[Tested Mutation], 
  mp.[Testing Gene 2], mp.[Testing Exon 2],  mp.[Tested Mutation 2], 
  mt.[Test Name],      mp.[Result Reported], mp.[Date Received],
  mp.[gp#]
FROM 
  dbo.[Molecular Pathology] AS mp 
LEFT OUTER JOIN 
  dbo.[Molecular Select Tests] AS mst
  ON mp.ID = mst.ForKey -- Molecular Pathology has an ID column and an ID# column? 
LEFT OUTER JOIN 
  dbo.[Molecular Tests] AS mt
  ON mst.Test = mt.[Test Name]
WHERE 
  mp.[LIS SignOut] IS NULL;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM