I am making a stored procedure that would accept ID as a parameter and will bring one record related to the ID provided and if no ID were provided bring the whole result set back.
I have managed to make some workaround with COALESCE function but I really would like to have that input parameter as INTEGER data type.
Here's my code:
CREATE PROCEDURE GetThis
@ID VARCHAR(25) = NULL
SET @ID= COALESCE( @ID, '%' )
SELECT * FROM #TABLE
WHERE CONVERT(VARCHAR(25),ID) LIKE @ID
What is the best way to achieve this?