ironhide1975
Programmer
Greetings,
I'm still working through learning Stored Procedures and SQL language. I'm trying to set up a Stored Procedure that if a Search Variable is passed to the procedure that it uses that to search the fields, and if not, just return all results normally. If someone can help me possibly work through what I'm missing here, I would appreciate it.
I'm still working through learning Stored Procedures and SQL language. I'm trying to set up a Stored Procedure that if a Search Variable is passed to the procedure that it uses that to search the fields, and if not, just return all results normally. If someone can help me possibly work through what I'm missing here, I would appreciate it.
Code:
[sp_GetTXZipCodesListing](
@OrderByClause varchar(10) = NULL,
@Search varchar(50) = NULL,
@ID varchar(10) = NULL
)
AS
Select ID, Zipcode, County, City, [State], GSA_Name, GSA_Designation, Certified
From [ZIP-GSALookup]
WHERE Active = 1
AND (
(@Search IS NOT NULL AND ZipCode = @Search)
)
ORDER BY
CASE
WHEN @OrderByClause='ZipCode' THEN ZipCode + County + City
WHEN @OrderByClause='County' THEN County + ZipCode + City
END