创建存储过程create procedure proc_getAllemployeeInfo
@userName varchar(50),
@userID varchar(50),
@userDepartment varchar(50)
as
此处求一条SQL语句
select * from [User] (如果传入的3个参数都为null)如果有不为null的参数 则在后面加上 where userName = @userName。。该如何写这样一条SQL语句
@userName varchar(50),
@userID varchar(50),
@userDepartment varchar(50)
as
此处求一条SQL语句
select * from [User] (如果传入的3个参数都为null)如果有不为null的参数 则在后面加上 where userName = @userName。。该如何写这样一条SQL语句
@userName varchar(50),
@userID varchar(50),
@userDepartment varchar(50)
as
select *
from [User]
where username=ISNULL(@username,username)
and userid=ISNULL(@userid,userid)
and userDepartment=ISNULL(@userDepartment,userDepartment)
gotry
@userName varchar(50),
@userID varchar(50),
@userDepartment varchar(50)
as
declare @sql varchar(1000)
declare @sqlwhere varchar(1000)
set @sqlwhere = 'where 1=1 '
if @username is not null
set @sqlwhere = @sqlwhere + 'and username=''' +@username +''''
if @userID is not null
set @sqlwhere = @sqlwhere + 'and username=''' +@userID + ''''
if @userDepartment is not null
set @sqlwhere = @sqlwhere + 'and userDepartment =''' +@userDepartment + ''''set @sql = 'select * from [user] ' + @sqlwhere
Select * from [User] where username=ISNULL(@username,username) and userid=ISNULL(@userid,userid) and userDepartment=ISNULL(@userDepartment,userDepartment)
select * from [User] where userName = isnull(@userName,username)
create procedure proc_getAllemployeeInfo
@userName varchar(50),
@userID varchar(50),
@userDepartment varchar(50)
as
select *
from [User]
where username=ISNULL(@username,username)
and userid=ISNULL(@userid,userid)
and userDepartment=ISNULL(@userDepartment,userDepartment)
@userName varchar(50),
@userID varchar(50),
@userDepartment varchar(50)
as
begin
select * from [User]
where 1=1
and (userName=@userName or @userName is null)
and (userID=@userID or @userID is null)
and (userDepartment=@userDepartment or @userDepartment is null)
end
@userName varchar(50),
@userID varchar(50),
@userDepartment varchar(50)
as
begin
select * from [User]
where (userName=@userName or @userName is null)
and (userID=@userID or @userID is null)
and (userDepartment=@userDepartment or @userDepartment is null)
end
select * from [User] where (userName = @userName or @userName is Null)