title: How to pass column name in scalar function in sql server
body: <p>I am creating a scalar function in sql server.And passing column name as parameter in function.In this function I am using those column name with that table. Here <code>@FromCurrency</code> and <code>@ToCurrency</code> are column names of <code>CurrencyConversion</code> table.<br>
  Code as follows:</p>
  
  <pre><code>alter FUNCTION fnCurrencyConversion  --1200.90,'NGN','CAD' 
        (@MoneyAmount MONEY,
         @FromCurrency nvarchar(20),
         @ToCurrency nvarchar(20))  
  RETURNS decimal(18,2)  
  AS  
  BEGIN 
    declare @BaseToUsd nvarchar(1000), @UsdToTarget nvarchar(1000)
    declare @Rate decimal(18,5) 
    set @BaseToUsd= ('select top 1 '+ @FromCurrency  +' from CurrencyConversion order by id desc')
    set @UsdToTarget = ('select top 1 '+ @ToCurrency  +'  from CurrencyConversion order by id desc') 
  
    set @Rate = @UsdToTarget/@BaseToUsd
    declare @TotalAmt decimal(18,5)
    set @TotalAmt = (@Rate * @MoneyAmount)  
    return @TotalAmt 
  
  END 
  </code></pre>
  
  <p>How to pass column name in scalar valued function in sql?</p>