存储过程中执行存储过程,并把结果赋值给output参数
2012-08-14 14:29
477 查看
ALTER PROCEDURE [dbo].[xl_StockWarningQuery]
@nCargoID bigint,
@sCargoName varchar,
@nCargoSup int,
@nCargoBrand int,
@sAdminName varchar,
@pagesize int,
@pageindex int,
@count int output
AS
BEGIN
declare @sql nvarchar(4000)
declare @sql1 nvarchar(4000)
set @sql = 'select * from
(select
ROW_NUMBER() OVER (order by a.sName asc) rownumber,
a.nID as nCargoID,
a.sName as sCargoName,
c.sCompany as sSupName,
e.sName as sCargoSize,
f.sName as sCargoColor,
g.sBrandName as nCargoBrand,
b.nAmount as nCargoAmount,
b.nVAmount as nCargoVAmount
from xl_Cargo a
left join xl_Inventory b on a.nID = b.nCargoID
left join xl_Suppliers c on a.nSup = c.nID
left join xl_Admin d on c.nManager = d.nID
left join xl_Size e on a.nSizeClass = e.nID
left join xl_Color f on a.nColorClass = f.nID
left join xl_Brand g on a.nBrand = g.nID
where a.nType=1 and b.nVAmount <= 2';
if (@nCargoID > 0)
begin
set @sql = @sql + 'and a.nID = '+str(@nCargoID);
end
if (len(@sCargoName)>0)--
begin
set @sql = @sql + 'and a.sName = '+@sCargoName;
end
if (@nCargoSup>0)
begin
set @sql = @sql + 'and a.nSup = '+str(@nCargoSup);
end
if (@nCargoBrand>0)
begin
set @sql = @sql + 'and a.nBrand = '+str(@nCargoBrand);
end
if (len(@sAdminName)>0)
begin
set @sql = @sql + 'and d.sAdminName ='+@sAdminName;
end
set @sql = @sql +')t where t.rownumber between '+str(@pagesize*(@pageindex-1)+1)+' and '+str(@pagesize*@pageindex);
--返回总行数---------------------------------------------------------------------------------------------------------
--declare @MyTable table(nVal int)
set @sql1 = 'select @count_output = count(*)
from xl_Cargo a
left join xl_Inventory b on a.nID = b.nCargoID
left join xl_Suppliers c on a.nSup = c.nID
left join xl_Admin d on c.nManager = d.nID
left join xl_Size e on a.nSizeClass = e.nID
left join xl_Color f on a.nColorClass = f.nID
left join xl_Brand g on a.nBrand = g.nID
where a.nType=1 and b.nVAmount <= 2';
if (@nCargoID > 0)
begin
set @sql1 = @sql1 + 'and a.nID = '+str(@nCargoID);
end
if (len(@sCargoName)>0)--
begin
set @sql1 = @sql1 + 'and a.sName = '+@sCargoName;
end
if (@nCargoSup>0)
begin
set @sql1 = @sql1 + 'and a.nSup = '+str(@nCargoSup);
end
if (@nCargoBrand>0)
begin
set @sql1 = @sql1 + 'and a.nBrand = '+str(@nCargoBrand);
end
if (len(@sAdminName)>0)
begin
set @sql1 = @sql1 + 'and d.sAdminName ='+@sAdminName;
end
---------------------------------------------------------------------------------------------------------------------
exec sp_executesql @sql1, N'@count_output INT OUTPUT', @count_output = @count OUTPUT
exec(@sql)
END
@nCargoID bigint,
@sCargoName varchar,
@nCargoSup int,
@nCargoBrand int,
@sAdminName varchar,
@pagesize int,
@pageindex int,
@count int output
AS
BEGIN
declare @sql nvarchar(4000)
declare @sql1 nvarchar(4000)
set @sql = 'select * from
(select
ROW_NUMBER() OVER (order by a.sName asc) rownumber,
a.nID as nCargoID,
a.sName as sCargoName,
c.sCompany as sSupName,
e.sName as sCargoSize,
f.sName as sCargoColor,
g.sBrandName as nCargoBrand,
b.nAmount as nCargoAmount,
b.nVAmount as nCargoVAmount
from xl_Cargo a
left join xl_Inventory b on a.nID = b.nCargoID
left join xl_Suppliers c on a.nSup = c.nID
left join xl_Admin d on c.nManager = d.nID
left join xl_Size e on a.nSizeClass = e.nID
left join xl_Color f on a.nColorClass = f.nID
left join xl_Brand g on a.nBrand = g.nID
where a.nType=1 and b.nVAmount <= 2';
if (@nCargoID > 0)
begin
set @sql = @sql + 'and a.nID = '+str(@nCargoID);
end
if (len(@sCargoName)>0)--
begin
set @sql = @sql + 'and a.sName = '+@sCargoName;
end
if (@nCargoSup>0)
begin
set @sql = @sql + 'and a.nSup = '+str(@nCargoSup);
end
if (@nCargoBrand>0)
begin
set @sql = @sql + 'and a.nBrand = '+str(@nCargoBrand);
end
if (len(@sAdminName)>0)
begin
set @sql = @sql + 'and d.sAdminName ='+@sAdminName;
end
set @sql = @sql +')t where t.rownumber between '+str(@pagesize*(@pageindex-1)+1)+' and '+str(@pagesize*@pageindex);
--返回总行数---------------------------------------------------------------------------------------------------------
--declare @MyTable table(nVal int)
set @sql1 = 'select @count_output = count(*)
from xl_Cargo a
left join xl_Inventory b on a.nID = b.nCargoID
left join xl_Suppliers c on a.nSup = c.nID
left join xl_Admin d on c.nManager = d.nID
left join xl_Size e on a.nSizeClass = e.nID
left join xl_Color f on a.nColorClass = f.nID
left join xl_Brand g on a.nBrand = g.nID
where a.nType=1 and b.nVAmount <= 2';
if (@nCargoID > 0)
begin
set @sql1 = @sql1 + 'and a.nID = '+str(@nCargoID);
end
if (len(@sCargoName)>0)--
begin
set @sql1 = @sql1 + 'and a.sName = '+@sCargoName;
end
if (@nCargoSup>0)
begin
set @sql1 = @sql1 + 'and a.nSup = '+str(@nCargoSup);
end
if (@nCargoBrand>0)
begin
set @sql1 = @sql1 + 'and a.nBrand = '+str(@nCargoBrand);
end
if (len(@sAdminName)>0)
begin
set @sql1 = @sql1 + 'and d.sAdminName ='+@sAdminName;
end
---------------------------------------------------------------------------------------------------------------------
exec sp_executesql @sql1, N'@count_output INT OUTPUT', @count_output = @count OUTPUT
exec(@sql)
END
相关文章推荐
- 数据库操作_连接SQL Server数据库示例;连接ACCESS数据库;连接到 Oracle 数据库示例;SqlCommand 执行SQL命令示例;SqlDataReader 读取数据示例;使用DataAdapter填充数据到DataSet;使用DataTable存储数据库表;将数据库数据填充到 XML 文件;10 使用带输入参数的存储过程;11 使用带输入、输出参数的存储过程示;12 获得数据库中表的数目和名称;13 保存图片到SQL Server数据库示例;14 获得插入记录标识号;Exce
- 数据库技术_Orcale技术(0002)_5分钟会用存储过程_存储过程简单实例(包含循环、条件、增改查、参数传入、变量赋值、java调用等)
- 执行存储过程获取OUTput参数返回值
- Oracle 在函数或存储过程中执行sql查询字符串并将结果值赋值给变量
- dbutils 执行存储过程,dbutils 调用有输出参数的存储过程
- C#调用SQL中的存储过程中有output参数,存储过程执行过程中返回信息
- c#定义一个方法,根据存储过程名称和存储过程参数数组,执行对应的存储过程
- 关于ExecuteNonQuery执行存储过程的返回值 、、实例讲解存储过程的返回值与传出参数、、、C#获取存储过程的 Return返回值和Output输出参数值
- 【Mybatis】MyBatis调用带有返回结果、output参数的存储过程上与ibatis的区别
- MyBatis调用带有返回结果、output参数的存储过程上与ibatis的区别
- Entity Framework 执行存储过程的 获取 OutPut 参数的值
- 在数据库里执行 返回参数时,不是存储过程返回的值,而是跟在存储过程后面的那个@output变量
- 在存储过程中使用另一个存储过程返回的查询结果集
- 在存储过程中执行存储过程
- [Database]创建存储过程并在ASP.NET中的调用带参数的存储过程与及调用带参数的SQL语句对比
- 存储过程输出参数:C#中调用输入输出参数的存储过程
- MS-SQL 执行一个参数为GUID的存储过程
- 存储过程中如何根据参数是否为空执行不同的select??
- ado执行存储过程中包含结果集获取输出参数为VT_EMPTY
- 遍历数据库中的用户存储过程,获得每个存储过程的参数名、参数类型、存储过程名称等信息以xml的形式保存