I need a database variable because the tables from which I'm accessing data will be in various databases, such as dBase1, dBase2, etc. I cannot use Select... in a string, because I want to use the Select statement into a cursor, which does not appear to allow the use of strings and the exec command. Here is an example that does not work. Any advice is appreciated...
DECLARE @fromDBase varchar(10), @FundCD char(4), @actID INT,
@PortCode char(4), @FundDecm INT, @PlanCd char(6)
set @FundCD = 'F0XX'
set @actID = 11135408
set @PortCode = 'P001'
set @FundDecm = 3
set @PlanCd = 'XXX001'
DECLARE csFin cursor STATIC LOCAL for
SELECT PortionCode, CashValue, UnitValue, CostValue, UniqueID
from (SELECT DatabaseName FROM [dBase1].[dbo].mPTLDetail WHERE plancode = @PlanCd)
WHERE AccountID = @actID
AND FundCode = @FundCd
AND UnitValue != 0
AND (Cast(Str(UnitValue, 12, @FundDecm) as money) - UnitValue) != 0