I'm not quite sure how to ask this, but let me ask an example:
I have a table for which I can not change the structure. It registers cash deposits at terminals like ATM and has one column for each denomination of cash. Now, when I need the full value of the deposit, I need the code:
(rd.Count_R10 * 10) + (rd.Count_R20 * 20) + (rd.Count_R50 * 50) + (rd.Count_R100 * 100) + (rd.Count_R200 * 200)
I would like to write a T-SQL function that gives me this common value, but for any row, not for the whole query, so my function will look something like this:
CREATE FUNCTION DepositTotal ( @row ???? ) RETURNS money AS BEGIN RETURN (row.Count_R10 * 10) + (row.Count_R20 * 20) + (row.Count_R50 * 50) + (row.Count_R100 * 100) + (row.Count_R200 * 200) END
Then I would call it something like:
select DepositDate , DepositTotal(thisRow) , BatchId from Deposits
sql-server tsql sql-server-2005
Profk
source share