Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Brain dead - SQL syntax
Message
 
 
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01253096
Message ID:
01253212
Views:
21
>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--
Previous
Reply
Map
View

Click here to load this message in the networking platform