|M| 从零开始学习存储过程第三贴:一条存储过程返回值
create procedure test(@name varchar,@TypeId int)
as
declare @sql varchar(512)
declare @iWhere varchar(32)
set @sql= "select * from tab "
set @iWhere= " where 1=1 "
if(name <> " ")
begin
set @iWhere =@iWhere + " And Name like '% " + Name + "% ' ";
end
if(TypeID <> -1)
begin
set @iWhere =@iWhere + "And TypeID = " + TypeID;
end
set @sql=@sql + @iWhere;
EXECUTE sp_executesql @sql
-----------------------------------------
1:在这里如果我还想得到返加有多少记录上面要添加哪些
2:如何查询CSDN中的贴子如:包含 "|M| " 和 "存储过程 " 这样的贴了
------解决方案--------------------jf
------解决方案--------------------create procedure test(@name varchar,@TypeId int, @count int output)
as
declare @sql varchar(512)
declare @iWhere varchar(32)
set @sql= "select * from tab "
set @iWhere= " where 1=1 "
if(name <> " ")
begin
set @iWhere =@iWhere + " And Name like '% " + Name + "% ' ";
end
if(TypeID <> -1)
begin
set @iWhere =@iWhere + "And TypeID = " + TypeID;
end
set @sql=@sql + @iWhere;
set @count = @@ROWCOUNT
EXECUTE sp_executesql @sql
再读取@count的值。
------解决方案--------------------楼上的好像没有对@count 进行定义吧
=====
参数中有了.
------解决方案--------------------补充
读取:string count = CMD.Parameters(@count).Value.ToString()