I want to create a single selective stored procedure for SQL 2005 that is universal for any select query in this table.
**Columns**
LocationServiceID
LocationID
LocationServiceTypeID
ServiceName
ServiceCode
FlagActive
For this table, I may need to select LocationServiceID or LocationID, LocationServiceTypeID or ServiceName, or a combination of the above.
I would prefer not to have a separate stored procedure for each of them.
I guess the best way to do this is to construct the WHERE statement on NOT NULL. Sort of
SELECT * FROM LocationServiceType WHERE
IF @LocationID IS NOT NULL (LocationID = @LocationID)
IF @LocationServiceID IS NOT NULL (LocationServiceID = @LocationServiceID)
IF @LocationServiceTypeID IS NOT NULL (LocationServiceTypeID = @LocationServiceTypeID)
IF @ServiceName IS NOT NULL (ServiceName = @ServiceName)
IF @ServiceCode IS NOT NULL (ServiceCode = @ServiceCode)
IF @FlagActive IS NOT NULL (FlagActive = @FlagActive)
It makes sense?
source
share