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 2000 Forums
 SQL Server Development (2000)
 cross database sql statement in stored procedure

Author  Topic 

logicmechanic
Starting Member

4 Posts

Posted - 2009-01-14 : 16:26:12
Simple select statement to a table in a different database (same sql server 2000 install) does not return anything. No errors, no indication what the problem is. the statement:
select @BU = BalanceUnits, @UU = UsedUnits from dbProduct.dbo.tblUnits where UnitID = @ID
Is there some trick I should know about? Permissions maybe?

Thank you.

logicmechanic
Starting Member

4 Posts

Posted - 2009-01-14 : 16:42:59
I forgot to mention, if I take the statement out of the stored procedure and modify it to just return a record, it works. I am using debug the stored procedure in Query analyzer.
Go to Top of Page

rohitkumar
Constraint Violating Yak Guru

472 Posts

Posted - 2009-01-14 : 16:46:48
its simply setting values of variables @BU and @UU and will not return anything
do a
SELECT @BU, @UU
after your select to check.
Go to Top of Page

logicmechanic
Starting Member

4 Posts

Posted - 2009-01-14 : 17:02:27
This is inside a stored procedure and I am using debug the stored procedure in query analyzer. I can see the variables do not populate with the data from the dbProduct.dbo.tblUnits table which resides in a different database even though it is the same sql server install.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-14 : 17:06:47
If it doesn't return anything, then the variables are NULL due to no rows matching the query.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

logicmechanic
Starting Member

4 Posts

Posted - 2009-01-15 : 11:21:59
Thank you Tara. I must have been tired yesterday when thinking about this. You are correct, there was no row returned on the select. I will now build in accounting for that very scenario.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-15 : 11:58:47
You're welcome.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -