I’ve a table
create table user (userId varchar(8) not null, userName varchar(8) not null)
insert into user
select 'NAME1','name1'
union all
select 'NAME2', 'name2'
union all
select 'NAME3','name3'
I’ve used stored procedure for wild card parameters as:
create procedure wildcard_name
@userName nchar(8)= '%'
as
select * from user
where userName like @userName;
exec wildcard_name 'n%';
the exec statement is not giving any result,why?
Did you try running it again? I suspect the exec call is part of the body of your procedure now. How about:
Bunch of other suggestions I would be remiss to not mention:
CREATE PROCEDURE dbo.wildcard_name,EXEC dbo.wildcard_name, etc.SELECT *.BEGIN/ENDand don’t be afraid to use indenting to make it much more readable.SET NOCOUNT ON;to preventn row(s) affectedmessages from interfering with your results.NVARCHARparameters should have an N prefix (though I’m confused why you’re alternating betweenvarcharandncharin the first place – this is two shifts where I’d expect zero).COLLATEclause.EDIT this seems to work just fine for me, so please explain what you are doing differently (and does “did not work” still mean empty result, or something else?):