Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Using SqlFacet Attributes for an SQL function

Using SqlFacet Attributes for an SQL function

Scheduled Pinned Locked Moved Database
csharpdatabasesysadminhelptutorial
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Johnny 0
    wrote on last edited by
    #1

    Hi, I wrote a function in C# to be used as a scalar function in SQL2005: [Microsoft.SqlServer.Server.SqlFunction(IsPrecise = true, IsDeterministic = true, DataAccess = DataAccessKind.Read)] public static SqlDecimal GetTaxAmountFromTax(SqlString tax, SqlDecimal amount) { SqlConnection conn = new SqlConnection("context connection=true"); SqlDataAdapter adap = new SqlDataAdapter("SELECT * FROM TransactionTaxes", conn); DataTable taxTable = new DataTable(); adap.Fill(taxTable); DataRow[] rows = taxTable.Select("[ID] = '" + tax.ToString() + "'"); if (rows.Length == 0) return SqlDecimal.Null; if (rows[0]["CalculatedOnTax"] != DBNull.Value) { if ((bool)rows[0]["Cumulative"]) { DataRow[] rows1 = taxTable.Select("[ID] = '" + rows[0]["CalculatedOnTax"].ToString() + "'"); if (rows1.Length == 0) return SqlDecimal.Null; return ((amount + (amount * (decimal)rows1[0]["Rate"]) / new SqlDecimal(100))) * (decimal)rows[0]["Rate"] / new SqlDecimal(100); } else return amount * (decimal)rows[0]["Rate"] / new SqlDecimal(100); } else return amount * (decimal)rows[0]["Rate"] / new SqlDecimal(100); } I want to publish this function making sure the return type has a precision of 2 and a scale of 18. I found that I have to use the SqlFacetAttributes but I am unsure how to do it for a function. I found examples only for a Strored Procedure parameter. Any help appreciated. Txs

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups