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