当前位置:首页 » 编程语言 » csql返回

csql返回

发布时间: 2025-01-29 09:42:18

‘壹’ c#怎么和sql数据库连接

1、打开Visual Studio 2008工具,点击文件菜单,选择新建下面的项目选项,如下图所示。

‘贰’ SQL Server 在一个存储过程中调用另外一个存储过程获取返回值,出现报错

第一种方法: 使用output参数

USE AdventureWorks;
GO
IF OBJECT_ID ( 'Proction.usp_GetList', 'P' ) IS NOT NULL
DROP PROCEDURE Proction.usp_GetList;
GO
CREATE PROCEDURE Proction.usp_GetList @proct varchar(40)
, @maxprice money
, @compareprice money OUTPUT
, @listprice money OUT
AS
SELECT p.name AS Proct, p.ListPrice AS 'List Price'
FROM Proction.Proct p
JOIN Proction.ProctSubcategory s
ON p.ProctSubcategoryID = s.ProctSubcategoryID
WHERE s.name LIKE @proct AND p.ListPrice < @maxprice;
-- Populate the output variable @listprice.
SET @listprice = (SELECT MAX(p.ListPrice)
FROM Proction.Proct p
JOIN Proction.ProctSubcategory s
ON p.ProctSubcategoryID = s.ProctSubcategoryID
WHERE s.name LIKE @proct AND p.ListPrice < @maxprice);
-- Populate the output variable @compareprice.
SET @compareprice = @maxprice;
GO

另一个存储过程调用的时候:

Create Proc Test
as
DECLARE @compareprice money, @cost money
EXECUTE Proction.usp_GetList '%Bikes%', 700,
@compareprice OUT,
@cost OUTPUT
IF @cost <= @compareprice
BEGIN
PRINT 'These procts can be purchased for less than
$'+RTRIM(CAST(@compareprice AS varchar(20)))+'.'
END
ELSE
PRINT 'The prices for all procts 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)
exec GetUserName

select #tempTable

--用完之后要把临时表清空
drop table #tempTable--需要注意的是,这种方法不能嵌套。例如:

procere a
begin
...
insert #table exec b
end

procere b
begin
...
insert #table exec c
select * from #table
end

procere c
begin
...
select * from sometable
end

--这里a调b的结果集,而b中也有这样的应用b调了c的结果集,这是不允许的,
--会报“INSERT EXEC 语句不能嵌套”错误。在实际应用中要避免这类应用的发生。

第三种方法:声明一个变量,用exec(@sql)执行:

1);EXEC 执行SQL语句

declare @rsql varchar(250)
declare @csql varchar(300)
declare @rc nvarchar(500)
declare @cstucount int
declare @ccount int
set @rsql='(select Classroom_id from EA_RoomTime where zc='+@zc+' and xq='+@xq+' and T'+@time+'=''否'') and ClassroomType=''1'''
--exec(@rsql)
set @csql='select @a=sum(teststucount),@b=sum(classcount) from EA_ClassRoom where classroom_id in '
set @rc=@csql+@rsql
exec sp_executesql @rc,N'@a int output,@b int output',@cstucount output,@ccount output--将exec的结果放入变量中的做法
--select @csql+@rsql
--select @cstucount

热点内容
服务器怎么设置电脑远程端口 发布:2025-07-03 16:28:46 浏览:72
电信无线路由器官方密码是什么 发布:2025-07-03 16:25:00 浏览:773
空间只能申请访问 发布:2025-07-03 16:23:27 浏览:735
华硕天选2air配置如何选择 发布:2025-07-03 16:10:09 浏览:571
asp搜索源码 发布:2025-07-03 15:49:55 浏览:235
医美大数据库 发布:2025-07-03 15:47:07 浏览:357
c语言将二进制转化为十进制 发布:2025-07-03 15:32:47 浏览:988
c语言帮助文档 发布:2025-07-03 15:22:43 浏览:320
双端口存储器在情况下会发生读写冲突 发布:2025-07-03 15:12:54 浏览:271
快站数据库 发布:2025-07-03 14:45:44 浏览:40