/*
exec usp_finddatawithout_para ''
exec usp_finddatawithout_para '1'
*/
create proc usp_finddatawithout_para
(
@empid varchar(50) = null
)
as
begin
declare @sql varchar(max),@eid varchar(500)
if @empid <>''
select @eid='and e.id=' + char(39) + @empid + char(39)
else
select @eid=''
select @sql='select name from emp e where 1=1 '+@eid+''
execute(@sql)
end
--or:--
if exists (select name from emp where id = @empid)
begin
select name from emp where id = @empid
end
begin
select name from emp
end
exec usp_finddatawithout_para ''
exec usp_finddatawithout_para '1'
*/
create proc usp_finddatawithout_para
(
@empid varchar(50) = null
)
as
begin
declare @sql varchar(max),@eid varchar(500)
if @empid <>''
select @eid='and e.id=' + char(39) + @empid + char(39)
else
select @eid=''
select @sql='select name from emp e where 1=1 '+@eid+''
execute(@sql)
end
--or:--
if exists (select name from emp where id = @empid)
begin
select name from emp where id = @empid
end
begin
select name from emp
end
0 Comments
if you have any doubts , please let me know