我们需要建立一个script
这将insert
只有新created
offices
和districts
成Data table
.我们需要检查两者Office
和District
tables
新的Records
,如果数据存在,我们需要insert
它们.
我们试过以下语法,
IF EXISTS ( SELECT 1 FROM [dbo].[office] o LEFT OUTER JOIN [dbo].[Datatable] a ON (o.OfficeID = a.OfficeID) WHERE a.OfficeID IS NULL ) OR ( IF EXISTS ( SELECT 1 FROM [dbo].[District] o LEFT OUTER JOIN [dbo].[Datatable] a ON (o.DistrictID = DistrictID) WHERE a.DistrictID IS NULL ) ) BEGIN -- //CODE END
但SSMS给出syntax error
了这一点.如何实现上述场景?
它应该是... OR EXISTS(
代替OR ( if EXISTS(
:
IF EXISTS ( SELECT 1 FROM [dbo].[office] o LEFT OUTER JOIN [dbo].[Datatable] a ON (o.OfficeID = a.OfficeID ) WHERE a.OfficeID IS NULL ) OR EXISTS ( SELECT 1 FROM [dbo].[District] o LEFT OUTER JOIN [dbo].[Datatable] a ON (o.DistrictID = DistrictID ) WHERE a.DistrictID IS NULL ) BEGIN //CODE END