-- -- Use the Specify Values for Template Parameters -- command (Ctrl-Shift-M) to fill in the parameter -- values below. -- -- This block of comments will not be included in -- the definition of the function. -- ================================================ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE NonNullAiAjAkAh ( -- Add the parameters for the function here @attributeName1 varchar(50), @attributeName2 varchar(50), @attributeName3 varchar(50), @attributeName4 varchar(50) ) AS BEGIN DECLARE @NonNullAiAj INT; DECLARE @NonNullAkAh INT; DECLARE @res INT; -- Add the SELECT statement with parameter references here IF ((SELECT count(name) FROM sys.tables WHERE name='aux1')=1) DROP TABLE aux1; IF ((SELECT count(name) FROM sys.tables WHERE name='aux2')=1) DROP TABLE aux2; CREATE TABLE aux1 (task varchar(50) primary key); INSERT INTO aux1 (task) ( SELECT distinct a1.idEvent FROM dbo.CorrelationAttributes as a1 WHERE (a1.attribute = @attributeName1 OR a1.attribute = @attributeName2) and a1.value is not null and not a1.value='' ); CREATE TABLE aux2 (task varchar(50) primary key); INSERT INTO aux2 (task) ( SELECT distinct a1.idEvent FROM dbo.CorrelationAttributes as a1 WHERE (a1.attribute = @attributeName3 OR a1.attribute = @attributeName4) and a1.value is not null and not a1.value='' ); --Intersección SELECT @res = COUNT(aux1.task) FROM aux1, aux2 WHERE aux1.task=aux2.task; --PRINT @res; IF ((SELECT count(name) FROM sys.tables WHERE name='aux1')=1) DROP TABLE aux1; IF ((SELECT count(name) FROM sys.tables WHERE name='aux2')=1) DROP TABLE aux2; IF ((SELECT count(name) FROM sys.tables WHERE name='ConjNonNull')=1) DROP TABLE ConjNonNull; CREATE TABLE ConjNonNull(name varchar(50) primary key, value real); INSERT INTO ConjNonNull VALUES ('ConjNonNull', @res); END; GO