主题:[讨论]求救,请高手帮忙。
用SQL编写一个存储过程无论用户输入多少个参数,都能得出相应的答案。我是这样写的:
use pubs
go
create proc Myproc @job_desc varchar(50)=null,@min_lvl int=null
as
declare @con int
set @con=0
if (@job_desc<>null)
set @con=1
if (@min_lvl<>null)
if (@con=0)
set @con=2
else
set @con=3
if (@con=0)
select * from jobs
if (@con=1)
select * from sales
if (@con=2)
select * from stores
if (@con=3)
select * from titles
go
但是得不到我想要的,请各位高手帮一把。谢谢。
use pubs
go
create proc Myproc @job_desc varchar(50)=null,@min_lvl int=null
as
declare @con int
set @con=0
if (@job_desc<>null)
set @con=1
if (@min_lvl<>null)
if (@con=0)
set @con=2
else
set @con=3
if (@con=0)
select * from jobs
if (@con=1)
select * from sales
if (@con=2)
select * from stores
if (@con=3)
select * from titles
go
但是得不到我想要的,请各位高手帮一把。谢谢。