我有一个这样的存储过程(缩短到最低限度):
CREATE PROCEDURE [dbo].[proc_Foo]
-- Add the parameters for the stored procedure here
@StyleNumber int,
@App nvarchar(50),
@User nvarchar(20)
AS
BEGIN
DECLARE @UserChar varchar(1) = 'U'
-- User with App
SELECT [StyleType],
[Value], 'UA' AS 'DerivedFrom'
FROM daten.dbo.GridStyleLocal
WHERE [StyleAssign] = @UserChar
AND [User] = @User
AND [StyleNumber] = @StyleNumber
AND [Application] = @App
UNION
-- Global (Basis) with app
SELECT [StyleType],
[Value], 'GA' AS 'DerivedFrom'
FROM basis.dbo.GridStyle
WHERE [StyleNumber] = @StyleNumber
AND [Application] = @App
AND [StyleType] NOT IN (
SELECT [StyleType]
FROM daten.dbo.GridStyleLocal
WHERE [StyleAssign] = @UserChar
AND [User] = @User
AND [StyleNumber] = @StyleNumber
AND [Application] = @App)
UNION
-- Scrape missing StyleTypes from Number 0
SELECT [StyleType],
[Value], 'G0A' AS 'DerivedFrom'
FROM basis.dbo.GridStyle
WHERE [StyleNumber] = 0
AND [Application] = @App
AND [StyleType] NOT IN (
SELECT [StyleType]
FROM daten.dbo.GridStyleLocal
WHERE [StyleAssign] = @UserChar
AND [User] = @User
AND [StyleNumber] = @StyleNumber
AND [Application] = @App)
AND [StyleType] NOT IN (
SELECT [StyleType]
FROM basis.dbo.GridStyle
WHERE [StyleNumber] = @StyleNumber
AND [Application] = @App)
END
GO
现在StyleNumber
0 是我的基本风格。StyleType
所有不在另一个中的属性( )都是StyleNumber
从 0 派生的。但是现在如果我在设置为 0时StyleNumber
包含第二个SELECT
(Global (Basis) with app),则该值是 GA 而不是 G0A。@StyleNumber
DerivedFrom
那么,如果为 0,是否有任何条件可以将其排除SELECT
在联合之外@StyleNumber
?