SQL一个存储过程调用另一个存储过程 获得返回值问题
第一种方法: 使用output参数
USE AdventureWorks;
GO
IF OBJECT_ID ( 'Production.usp_GetList', 'P' ) IS NOT NULL
DROP PROCEDURE Production.usp_GetList;
GO
CREATE PROCEDURE Production.usp_GetList @product varchar(40)
, @maxprice money
, @compareprice money OUTPUT
, @listprice money OUT
AS
SELECT p.name AS Product, p.ListPrice AS 'List Price'
from Production.Product p
JOIN Production.ProductSubcategory s
ON p.ProductSubcategoryID = s.ProductSubcategoryID
WHERE s.name LIKE @product AND p.ListPrice < @maxprice;
-- Populate the output variable @listprice.
SET @listprice = (SELECT MAX(p.ListPrice)
from Production.Product p
JOIN Production.ProductSubcategory s
ON p.ProductSubcategoryID = s.ProductSubcategoryID
WHERE s.name LIKE @product AND p.ListPrice < @maxprice);
-- Populate the output variable @compareprice.
SET @compareprice = @maxprice;
GO
另一个存储过程调用的时候:
Create Proc Test
as
DECLARE @compareprice money, @cost money
EXECUTE Production.usp_GetList '%Bikes%', 700,
@compareprice OUT,
@cost OUTPUT
IF @cost <= @compareprice
BEGIN
PRINT 'These products can be purchased for less than
$'+RTRIM(CAST(@compareprice AS varchar(20)))+'.'
END
ELSE
PRINT 'The prices for all products in this category exceed
$'+ RTRIM(CAST(@compareprice AS varchar(20)))+'.'
第二种方法:创建一个临时表
create proc GetUserName
as
begin
select 'UserName'
end
Create table #tempTable (userName nvarchar(50))
insert into #tempTable(userName)
相关文档:
大批量插入数据时 1,myisam表,可以先通过 alter table table_name disable keys;#先关闭表的索引检查,注意是非唯一索引! load data infile ‘/path/file’ into table table_name; alter table table_name anable keys;#再打开索引 可大大加快导入.还有可以设置bulk_insert_buffer_size值来提高插入速度 ......
写程序的人,往往需要分析所写的SQL语句是否已经优化过了,服务器的响应时间有多快,这个时候就需要用到SQL的STATISTICS状态值来查看了。
通过设置STATISTICS我们可以查看执行SQL时的系统情况。选项有PROFILE,IO ,TIME。介绍如下:
SET STATISTICS PROFILE ON:显示分析 ......
在Excel中,我们时常会碰到这样的字段(最常见的就是电话号码),即有纯数字的(如没有带区号的电话号码),又有数字和其它字符混合 (如“区号-电
话号码”)的数据,在导入SQLServer过程中,会发现要么纯数字的数据导过去之后变成了NULL,要么就是数字和其它字符混合的数据导过去之后变成
了NULL。
&n ......
SQL注入简单分析
示例语句:
select * from admintable where adminName like '%a%'
在查询中我们一般在a这个地方由界面传入不同的值,当我们在a这里传入的值为“'”单引号时,拼凑成的SQL语句就如下:
select * from admintable where adminName like '%'%'
执行这句语句我们会发现出现以下异常:
......
在使用ODP.NET进行Oracle编程时,有时候SQL语句非常复杂,需要采用动态构造查询语句的情况,有两种方法可以构造动态的SQL语句,并执行返回结果集。
1、在数据访问层构造SQL语句
例如下面的语句,将构造完整的SQL语句赋值给CommandText,再传递到数据库进行执行,返回结果集。
loadCommand.CommandType = Com ......