Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 exec sp

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2013-02-19 : 02:33:11
Hi,
inside a stored procedure which is created in databaseA I would like to pull the data from databaseB and place it into a table variable as follows

create procedure uspGetData

@Date date, @value bit

as

declate @tblData table
(
field1 varchar(50), field2 date
)

--insert into tblData
exec DatabaseB.dbo.uspAnotherProcedure @Date=@Date, @value=@value

Note that the above sp does indeed execute the stored proc in databaseB BUT if I take out the commented line i.e. insert into, then it fails and the message is:
A severe error occurred on the current command. The results, if any, should be discarded.

Any thoughts please?
Thanks

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-02-19 : 03:58:25
That statement should be
insert into @tblData


USE study
GO
CREATE PROCEDURE uspAnotherProcedure
AS
SELECT employee_id, department_id, salary FROM employees WHERE department_id Is null

USE DB2
GO
CREATE procedure uspGetData
As
BEGIN
declare @tblData table( empid INT, deptid INT, sal DEC(8,2))
insert into @tblData
exec study.dbo.uspAnotherProcedure
SELECT * FROM @tblData
END
EXEC uspGetData


--
Chandu
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2013-02-19 : 04:06:37
Thanks
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-02-19 : 04:54:29
quote:
Originally posted by arkiboys

Thanks

Welcome

--
Chandu
Go to Top of Page
   

- Advertisement -