我遇到一个问题,用户在<gt<=>=,=然后使用它来创建where条件。
create function salary(@salary int, @operator char(2))
returns table
return select dbo.NHANVIEN.HOTEN, dbo.NHANVIEN.LUONG from dbo.NHANVIEN
(case @sosanh when '>' then (where @sosanh+ @mucluong) end )
这是不可能的或
create function salary(@salary int, @operator char(2))
returns @table table(name nvarchar(10), luong int)
as
begin
if(@operator = '>')
begin
insert into @table
select dbo.NHANVIEN.HOTEN, dbo.NHANVIEN.LUONG from dbo.NHANVIEN where dbo.NHANVIEN.LUONG > @salary
end
if(@operator = '<')
begin
insert into @table
select dbo.NHANVIEN.HOTEN, dbo.NHANVIEN.LUONG from dbo.NHANVIEN where dbo.NHANVIEN.LUONG < @salary
end
.........
end
这真的不能比这快吗?
你想要吗
create function salary(@salary int, @operator char(2))
returns table
return
select nh.HOTEN, nh.LUONG
from dbo.NHANVIEN nh
where (@operator = '>' and nh.LUONG > @salary
or @operator = '<' and nh.LUONG < @salary
...
)