Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How To Handle No Params Passed
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 6.5 and older
Divers
Thread ID:
01359989
Message ID:
01359996
Vues:
17
That's one of the most asked questions on ASP.NET/Forums website. Assuming no parameters passed means NULL as a value for the parameter, you may try one of these

Where (@MyParm IS NULL or myField = @myParm)

or you may try

myField = ISNULL(@myParm, myField)

>I have this proc:
>
>
>CREATE PROCEDURE bm_GetProjects
>	@AppKey			int,
>	@CategoryKey	int,
>	@StatusKey		int
>
>AS
>BEGIN
>
>	SELECT p.ProjectKey, p.ProjectName, p.ProjectCode, p.RateAmt, p.EstHours, p.EstStartDate,
>		   p.EstEndDate, p.TotalHours, p.StartDate, p.EndDate, p.PercentDone,
>		   p.CategoryKey, pc.CategoryName,
>		   p.RateTypeKey, rt.TypeName AS RateTypeName,
>		   p.StatusKey, psc.ProjectStatusCodeName AS StatusCode,
>		   p.PriorityKey, pr.PriorityName AS Priority,
>		   p.ManagerKey, LTRIM(RTRIM(e.LastName)) + ' ' + e.FirstName AS ManagerName
>		FROM bm_Projects p
>		JOIN bm_RateTypes rt ON rt.TypeKey = p.RateTypeKey
>		JOIN bm_PrjCategories pc ON pc.CategoryTypeKey = p.CategoryKey
>		JOIN bm_Priorities pr ON pr.PriorityKey = p.PriorityKey
>		JOIN bm_ProjectStatusCodes psc ON psc.ProjectStatusCodeKey = p.StatusKey
>		LEFT JOIN bm_Employees e ON e.EmployeeKey = p.ManagerKey
>		WHERE p.AppKey = @AppKey AND
>			  pc.CategoryTypeKey = @CategoryKey AND
>			  psc.ProjectStatusCodeKey = @StatusKey
>		ORDER BY ProjectName
>
>END
>
>
>
>It's possible for any combination of parameters to be passed. How do I change the WHERE clause to handle this?
>
>Thanks
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform