create FUNCTION [dbo].[udfCurrencyAlternate] (@Currency nvarchar(10),@Date datetime,@Price float,@CurrAlt varchar(3))
RETURNS
float AS
BEGIN
declare @curRate float
declare @udfCurrency float
declare @CurrField varchar(4)
declare @KursID int
declare @Sql varchar(100)
set @CurrField=(select cField from dbo.tblCurrency where cID=@Currency)
set @KursID=(select cID from dbo.tblKurs where cDateStart<=@Date and cDateFinish>=@Date)
set @Sql='Select '+@CurrField+ ' from tblKurs where cID='+ convert(varchar,@KursID)
---/ tadinya disini pengen langsung aja seperti ini set @Sql='Select '+@CurrField+ ' from tblKurs where cDateStart<='+@Date+' and cDateFinish>='+@Date
jadi nggak perlu set @KursID, cuma nggak keluar hasilnya (filternya nggak ke detect)
if @CurrAlt=@Currency
begin
set @curRate=1
end
else
set @curRate=convert(int,@Sql)
Return
(@Price/@curRate)
END
Reply via web post | Reply to sender | Reply to group | Start a New Topic | Messages in this topic (1) |
Tidak ada komentar:
Posting Komentar