Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Values from two params without dups
Message
De
06/11/2010 12:24:11
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Versions des environnements
SQL Server:
SQL Server 2008
Divers
Thread ID:
01488455
Message ID:
01488458
Vues:
28
Wow, that was too easy. Thanks a bunch
Tim

>>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
>
>
>
>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 + ') OR
>              PostalCode = '+CAST(@PostalCode as varchar(10)
>	EXEC(@SQL)
>END
>
Timothy Bryan
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform