1.我在 t2里面调用 存储过程t1,提示 关键字 'exec' 附近有语法错误?
2.如果是存储过程,是不是临时表在存储过程执行完毕之后会自动释放资源create proc dbo.t1
as
select top 11 operatetime,theTypeName from ruhuo
go
----------------------------------------------------------------
create proc dbo.t2
as
select * into #tt from (exec t1)
select * from #tt
go
2.如果是存储过程,是不是临时表在存储过程执行完毕之后会自动释放资源create proc dbo.t1
as
select top 11 operatetime,theTypeName from ruhuo
go
----------------------------------------------------------------
create proc dbo.t2
as
select * into #tt from (exec t1)
select * from #tt
go
解决方案 »
- sql 关于多表关联 优化问题
- mysql区没高手
- mssql语句添加约束出错
- 不用一句编程代码,仅凭SQL SERVER2005加EXCELLENCE平台,我就做出了一套财务软件.华军为证http://onlinedown.net/soft/71391.htm
- sql:对字段排序并取其序号
- 分离再附加数据库后,数据文件和日志文件不增大,急啊!!!
- 多个表的查询
- Sql server表A 有些数据,我想让它生成insert into()这样的语句 以方便在其它数据库查询分析器中执行插入!有什么好的方法
- 数据库提示 文件组 'PRIMARY' 已满,求解决方法..
- 求助, 怎样在SQL server 7.0 上实现级联删除???
- 请问如何存储每个单元格数据
- 空值传入存储过程
create proc dbo.t2
as
create table #temp
(
……
)
insert into #temp
exec t1
select * into #tt from #temp
select * from #tt
go
create table tb(operatetime ..,theTypeName...)
insert into tb exec t1
as
select * into #tt from (exec t1)
select * from #tt
gocreate proc dbo.t2
as
create table #tt(....) --t1存储过程获得的结果集的结构
insert into #tt exec t1
go
as
select top 11 operatetime,theTypeName from ruhuo
go
----------------------------------------------------------------
create proc dbo.t2
as
Create table #tt(operatetime datetime,theTypeName nvarchar(100))
into #tt exec t1
select * from #tt
go
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'
endCreate table #tempTable (userName nvarchar(50))
insert into #tempTable(userName)
exec GetUserNameselect #tempTable--用完之后要把临时表清空
drop table #tempTable--需要注意的是,这种方法不能嵌套。例如: procedure a
begin
...
insert #table exec b
end
procedure b
begin
...
insert #table exec c
select * from #table
end
procedure 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本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/fredrickhu/archive/2009/09/23/4584118.aspx
create table
insert into table exec ---