Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Brain dead - SQL syntax
Message
 
 
À
07/09/2007 16:49:34
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01253096
Message ID:
01253212
Vues:
20
>Was my answer clear? I get two lists of qualifiers one list is required qualifiers and the other is excluded qualifiers. The selected records must have all required qualifiers and none of the exluded qualifiers.

And this one with dynamic sql
CREATE PROCEDURE GetContactsByQualities3 
	@Inc varchar(100), 
	@Exc varchar(100)
AS

DECLARE @CntInc int, @SQL varchar(4000)

SET @CntInc = LEN(@Inc) - LEN(REPLACE(@Inc, ',', '')) + 1
--PRINT @CntInc

SET @SQL = 'SELECT * FROM Contacts c ' +
	'WHERE ' + CAST(@CntInc AS varchar(20)) + ' = ' + 
			'(SELECT COUNT(*) FROM ContactQualities  
				WHERE contactid = c.id
					AND qualifierid IN (' + @Inc + '))'	+
			 '- (SELECT COUNT(*) FROM ContactQualities  
				WHERE contactid = c.id
					AND qualifierid IN (' + @Exc + '))'	

EXECUTE (@SQL)
RETURN 0
EXECUTE GetContactsByQualities3 @Inc = '1,5,11', @Exc = '2,6'
--sb--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform