Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Values from two params without dups
Message
 
 
À
06/11/2010 11:49: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:
01488460
Vues:
45
Did you try SELECT DISTINCT ?
You can do that w/o dynamic sql. Check http://www.berezniker.com/content/pages/sql/microsoft-sql-server/alines-udf-string-split and comments

>
>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
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform