使用参数创建sp
Create Procedure dbo.FetchStudentList_SP(@dpname varchar(100))
AS
Begin
Select s.Name,d.name,d.fees,d.staff as Department
From Student s With(Nolock)
full outer Join DepartMent d With(Nolock) On s.deptid = d.Id where d.name like ('%'+@dpname+'%')
End
执行具有某些值的sp
Exec FetchStudentList_SP'cs'
如果执行时没有给出任何值,我想查看以下代码 执行
Select s.Name,d.name,d.fees,d.staff as Department
From Student s With(Nolock)
full outer Join DepartMent d With(Nolock) On s.deptid = d.Id
任何人都可以说这可能吗?可能的话告诉我如何?
预先感谢
答案 0 :(得分:1)
如果您无法修改该过程,请尝试在调用该过程时传递空字符串。
这样的事情。
Exec FetchStudentList_SP '';
它将像执行查询一样
Select s.Name,d.name,d.fees,d.staff as Department
From Student s With(Nolock)
full outer Join DepartMent d With(Nolock) On s.deptid = d.Id where d.name like ('%%')
并且where条件将不起作用,但是如果不返回d.name为null的行。