Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Values from two params without dups
Message
From
06/11/2010 11:49:11
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Title:
Values from two params without dups
Environment versions
SQL Server:
SQL Server 2008
Miscellaneous
Thread ID:
01488455
Message ID:
01488455
Views:
128
Hi all,

I need to construct a Stored Procedure where I retrieve records from a single database table but I need to pass in two parameters. The first of which is a string that contains multiple values and I need all the records that match any of those values. I have done and tested this part. The second paramter would find records based on a single value but some of them could be duplicates to the first selection. I do not want any duplicates. Below is the procedure I did to test the first part, but how do I get my second selection where the records are NOT In the first selection and then return all the combined rows?

this is not the table I need to do this on as I don't have it right now, but I am testing on this table. The test values I passed in on my trial looked like this: "222, 2516, 23189" and then 14 for the second. This worked as expeced although the 14 is ignored so far.
ALTER PROCEDURE [dbo].[LocationSelectByThisAndThat]
(
	@AddressNumbers varchar(500),
	@PostalCode integer
)
AS
BEGIN
	SET NOCOUNT ON;
	DECLARE @SQL varchar(600)
	
	SET @SQL = 'SELECT 
		AddressNumber,
		ApartmentNumber,
		LastUpdated,
		LocationID,
		LocationTypeID,
		PostalCode,
		RecordStart,
		Status,
		StreetName,
		UpdatedBy
	FROM [dbo].[Location]
	WHERE 
		AddressNumber IN (' + @AddressNumbers + ')'
	EXEC(@SQL)
END
Thanks
Tim
Timothy Bryan
Next
Reply
Map
View

Click here to load this message in the networking platform