1) Here below is the SP def
CREATE PROC tblLoansAverageMargin_sp
(@DateFrom smalldatetime, @DateTo smalldatetime, @DateExcRate
smalldatetime,
@Days int)
AS
DELETE FROM ProfitabilitySQL.dbo.tblLoansAverageMargin
INSERT INTO ProfitabilitySQL.dbo.tblLoansAverageMargin
(LoanReference, CustomerNumber, BookCode, LastBusinessDate,
Currency, CurrentPrincipalAmount,
AverageVolume, TotalMonthlyMargin)
SELECT tblCorporateLoansGlobal.LoanReference,
tblCorporateLoansGlobal.CustomerNumber, tblCorporateLoansGlobal.BookCode,
MAX(tblCorporateLoansGlobal.BusinessDate),
tblCorporateLoansGlobal.Currency,
tblCorporateLoansGlobal.CurrentPrincipalAmount,
AverageVolume,SUM(tblCorporateLoansGlobal.DailyMargin) AS
TotalMonthlyMargin
SUM(tblCorporateLoansGlobal.VolumeAmount) AS
AverageVolume,SUM(tblCorporateLoansGlobal.DailyMargin) AS
TotalMonthlyMargin
FROM HVBMilanDataWareHouse.dbo.MidasCurrencysdcuhspd INNER JOIN
tblCorporateLoansGlobal ON
HVBMilanDataWareHouse.dbo.MidasCurrencysdcuhspd.Currency =
tblCorporateLoansGlobal.Currency
WHERE (HVBMilanDataWareHouse.dbo.MidasCurrencysdcuhspd.[Date] =
@DateExcRate) AND
((tblCorporateLoansGlobal.BusinessDate >= @DateFrom) AND
(tblCorporateLoansGlobal.BusinessDate <= @DateTo))
GROUP BY tblCorporateLoansGlobal.LoanReference,
tblCorporateLoansGlobal.CustomerNumber,
tblCorporateLoansGlobal.BookCode,
tblCorporateLoansGlobal.Currency,
tblCorporateLoansGlobal.CurrentPrincipalAmount
UPDATE ProfitabilitySQL.dbo.tblLoansAverageMargin
SET AverageEUROutstanding
=((ProfitabilitySQL.dbo.tblLoansAverageMargin.AverageVolume /
HVBMilanDataWareHouse.dbo.MidasCurrencysdcuhspd.[Exchange Rate]) / @Days),
TotalEURMarginIncome =
(ProfitabilitySQL.dbo.tblLoansAverageMargin.TotalMonthlyMargin /
HVBMilanDataWareHouse.dbo.MidasCurrencysdcuhspd.[Exchange Rate])
FROM ProfitabilitySQL.dbo.tblLoansAverageMargin INNER JOIN
HVBMilanDataWareHouse.dbo.MidasCurrencysdcuhspd ON
ProfitabilitySQL.dbo.tblLoansAverageMargin.Currency =
HVBMilanDataWareHouse.dbo.MidasCurrencysdcuhspd.Currency INNER JOIN
tblCorporateLoansGlobal ON
ProfitabilitySQL.dbo.tblLoansAverageMargin.LoanReference =
tblCorporateLoansGlobal.LoanReference AND
ProfitabilitySQL.dbo.tblLoansAverageMargin.CustomerNumber =
tblCorporateLoansGlobal.CustomerNumber AND
ProfitabilitySQL.dbo.tblLoansAverageMargin.Currency =
tblCorporateLoansGlobal.Currency
WHERE (HVBMilanDataWareHouse.dbo.MidasCurrencysdcuhspd.[Date] =
@DateExcRate) AND
(HVBMilanDataWareHouse.dbo.MidasCurrencysdcuhspd.MultiplyDivideIndicator =
'D')
UPDATE ProfitabilitySQL.dbo.tblLoansAverageMargin
SET AverageEUROutstanding
=((ProfitabilitySQL.dbo.tblLoansAverageMargin.AverageVolume *
HVBMilanDataWareHouse.dbo.MidasCurrencysdcuhspd.[Exchange Rate]) / @Days),
TotalEURMarginIncome =
(ProfitabilitySQL.dbo.tblLoansAverageMargin.TotalMonthlyMargin *
HVBMilanDataWareHouse.dbo.MidasCurrencysdcuhspd.[Exchange Rate])
FROM ProfitabilitySQL.dbo.tblLoansAverageMargin INNER JOIN
HVBMilanDataWareHouse.dbo.MidasCurrencysdcuhspd ON
ProfitabilitySQL.dbo.tblLoansAverageMargin.Currency =
HVBMilanDataWareHouse.dbo.MidasCurrencysdcuhspd.Currency INNER JOIN
tblCorporateLoansGlobal ON
ProfitabilitySQL.dbo.tblLoansAverageMargin.LoanReference =
tblCorporateLoansGlobal.LoanReference AND
ProfitabilitySQL.dbo.tblLoansAverageMargin.CustomerNumber =
tblCorporateLoansGlobal.CustomerNumber AND
ProfitabilitySQL.dbo.tblLoansAverageMargin.Currency =
tblCorporateLoansGlobal.Currency
WHERE (HVBMilanDataWareHouse.dbo.MidasCurrencysdcuhspd.[Date] =
@DateExcRate) AND
(HVBMilanDataWareHouse.dbo.MidasCurrencysdcuhspd.MultiplyDivideIndicator =
'M')
UPDATE ProfitabilitySQL.dbo.tblLoansAverageMargin
SET DateFrom = @DateFrom,
DateTo = @DateTo,
DateExc = @DateExcRate
GO
2) The script runs after on_click event - here below the statement:
CurrentProject.Connection.Execute cmdText, , adExecuteNoRecords
where cmdText is:
spName = "exec ProfitabilitySQL.dbo.tblLoansAverageMargin_sp "
cmdText = spName & " '" & Data1 & "'" & ", '" & Data2 & "'" & ", '" &
Data3 _
& "'" & ", '" & Forms![frmReportParameters]!Days &
"'"
Thanks for any suggestion
Malcolm Cook said:
Show us:
1) the exact definitino of the stored proc
2) the exact definition of the script that runs in the form (i.e. is it
an on_click event?)
Maybe that will helpp...???
--Malcolm
Thanks Phil, but it did not work either.
I changed the SP referencing all objects as dbname.owner.objectname but
I
still get the same problem. What is not clear to me is why if I launch
the SP
from Access without using the form it goes OK. I don't understand which
difference might be.
Thanks anyway
Best Regards
Mauro
:
Hi all. I'm experiencing the following problem: I have an ADP db
linked to
SQL Server 2000. Through a form I launch a SP using the method
CurrentProject.Connection.Execute and then open a report with a
DoCmd. The SP
initially empty a table using a DELETE and then populate it with
INSERT and
UPDATES. Now using my user everything is OK, the SP runs correctly
and the
report shows the expected results. Executing the same steps with a
different
user the SP runs partially (only the DELETE statement) and the table
remains
empty. I thought it was a permission problem on SQL but they are OK.
The
strangest thing is if I run the SP from Access without using the
form it
works with all users !!!!
Always(!) make sure you are using the full name including the owner of
the relevant object when adressing any SQL-Server object. E.g do _not_
just write
DELETE FROM myTable
but instead write
DELETE FROM username.myTable
Unless you are expressing yourself explicitely in this matter,
SQL-Server
will have to figure out by himself what object you actually meant. -
This
does not work as expected in every case...
The only exception to this rule is, when you really want diffrent
users
to affect diffrent object by executing the same sql.
Best wishes
Phil