如题:如何用一条SQL语句按输入的参数进行判断执行查询数据

2025-03-22 15:44:07
推荐回答(2个)
回答1:

select a.ID,a.name,sex,b.ID,b.name,old from A full join B on a.ID=b,ID order by a.ID;
按下列方式试试。
select a.ID,a.name,sex,b.ID,b.name,old from A full join B on a.ID=b,ID
where (a.name is null and a.sex is null and b.name is not null) or
(a.name is not null and a.sex is not null and b.name is null)
order by a.ID;

回答2:

declare @strsql nvarchar(1024),@ID int
set @strsql=''
if(@ID=3)
begin
select * from A
end
else if(@ID=4)
begin
select * from B
end
exec(@strsql)
不知道这样算不算一句