score:3

Accepted answer

to convert this into a sp you'll need to make variable1 a parameter. the iif part could be addressed in the where clause, like this:

create procedure [procedure_name] @variable1 varchar(50)
as
begin
    select *
    from id9codes
    where len(ltrim(rtrim(isnull(@variable1, '')))) = 0
        or code like @variable1 + '%'
end

Related Query

More Query from same tag