June 12, 2006 at 8:42 am
I know this is easier than I am making it, but I cannot seem to get this right...
I am building a function to calculate earned revenue based on when service is billed in relation to the service time. To do this I need to work with the start and end dates of the billing period, as well as the date of the invoice. All of these fileds are part of the transaction record, so selectign them is easy, but I do not know how to populate the variabls in the function. (I am more accustomed to Oracle where I would jsut use a select into statement)
So my question is this - what is the syntax for populating local varaible with query results? I have included the start of my function, as well as the query that will populate the variables.
Any help is greatly appreciated!
--Start of function
Create function earned(@input int)
Returns Decimal(14,6)
as
Begin
Declare @to_date datetime,
@from_date datetime,
@Cyc_end datetime,
@amount Decimal(14,6)
--query to populate variable
select
SD_TO_DATE,
SD_FROM_DATE,
SD_CYCEND,
SD_BILL_AMOUNT
from ovi_sd_record = @input
June 12, 2006 at 8:55 am
SELECT @to_date = SD_TO_DATE,
@from_date = SD_FROM_DATE,
@cyc_end = SD_CYCEND,
@amount = SD_BILL_AMOUNT
FROM table
WHERE ovi_sd_record = @input
That should work, unless ovi_sd_record is your table name. Your syntax is a little off I think in your example.
June 12, 2006 at 9:12 am
Thanks! That got wherei needed to be. I started out with somethign very similar to that, but it didn't work. I must have missed something. Anyway - I am rolling now- thanks for the help!
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply