SqlServer2005存储过程的编写(未完待续)
1)返回结果为参数
存储过程代码:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
CREATE PROCEDURE getStudentAmount
@recordCount int output
AS
begin
select @recordCount=count(*) from studentInfo;
end
测试代码:
XXXXXX
2)返回结果为数据集
存储过程代码:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
CREATE PROCEDURE queryAllStudentInfo
AS
begin
select * from studentInfo;
end
测试代码:
XXXXXXX
3)访问其他数据库中的表
存储过程代码:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
CREATE PROCEDURE get_i_dot
@i_dot_output int output
AS
BEGIN
select @i_dot_output=i_dot from fynow..codes where c_code_type=1;
END
注:访问其他数据库中的表,只需用【数据库名】..【表名】的形式即可,eg: fynow..codes
测试代码:
use EdisonDB;
declare @idot int
declare @idotString varchar(10)
exec get_i_dot @idot output;
set @idotString=cast(@idot as varchar)
print @idotString