首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

存储过程查询,该如何处理

2012-03-27 
存储过程查询以一张表每条记录中的三个字段作为条件,查另一张表,3个变量,该怎么写?[解决办法]select m.* ,

存储过程查询
以一张表每条记录中的三个字段作为条件,查另一张表,

3个变量,该怎么写?

[解决办法]
select m.* , n.*
from m ,n 
where m.关键字 = n.关键字 and
m.c1 = @变量1 and m.c2 = @变量2 and m.c3 = @变量3
[解决办法]

SQL code
create procedure pr_test(@v1 int,@v2 int,@v3 int)asbeginset nocount onselect b.* from a,b where a.id=b.a_id and b.v1=@V1 AND b.v2=@v2 and b.v3=@v3end或者create procedure pr_testasbeginset nocount ondeclare @v1 int,@v2 int,@v3 intselect @v1=v1,@v2=v2,@v3=v3 from a where 条件;select b.* from a,b where a.id=b.a_id and b.v1=@V1 AND b.v2=@v2 and b.v3=@v3end
[解决办法]
贴数据和结果出来。说的不清楚回答也不会清楚
[解决办法]
三个变量,任意组合,哈哈,花了俺几个钟头才搞定。希望能有用。


create proc up_selectemp
@empName nvarchar(20),
@departNO int,
@positionNO int

as

declare @sql varchar(500)
if(@departNO=0)
begin
declare @s1 varchar(100)
set @s1= ''
end
else
begin
set @s1 = 'and DepartNO='+convert (varchar ,@departNO)
end
if(@positionNO=0)
begin
declare @s2 varchar(100)
set @s2= ''
end
else
begin
set @s2 = ' and PositionNO='+convert (varchar,@positionNO)
end
set @sql=
'select empID, empName,dt.InfoName,p.InfoName,Intime,Tel,Email
from Employee 
join BasicInfo as dt on Employee .DepartNO=dt.InfoID
join basicinfo as p on Employee .PositionNO=p.InfoID
where empName like '+'''%' + @empName + '%''' +@s1+@s2
 
exec(@Sql)
go

热点排行