易截截图软件、单文件、免安装、纯绿色、仅160KB

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)


相关文档:

查看sql server 2000的版本的三种方法

方法一:
打开企业管理器->SQL SERVRE 组->(local)window NT ->属性
产品:有personal的是个人版的,有Enterprise的是企业版的
产品版本:8.00.2039(sp4);8.00.760(sp3)
方法二:
第一步:在查询分析器
select @@version
print @@version
Microsoft SQL Server 2000 - 8.00.2039 (Intel X86)
May 3 2005 ......

一个sql分页的存储过程

 CREATE  procedure SqlPager_Ex
 @sqlstr varchar(8000), --查询字符串
  @currentpage int, --第N页
  @pagesize int --每页行数, 
 as
  set nocount on
  declare @P1 int, --P1是游标的id
   @rowcount int
  exec sp_cursorope ......

怎么捕获自己session执行的sql,进行深入跟踪

 
alter session set timed_statistics = true; --可选
alter session set max_dump_file_size = unlimited; --可选,防止dump目录放不下
-- To enable the trace event 10046
alter session set events '10046 trace name context forever, level 8';
--设置TRACEFILE_IDENTIFIER参数值,让trace文件包括MyTrac ......

sql server日期时间函数

Sql Server中的日期与时间函数 
1.  当前系统日期、时间 
    select getdate()  
2. dateadd  在向指定日期加上一段时间的基础上,返回新的 datetime 值
   例如:向日期加上2天 
   sele ......

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
  &nb ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号