Skip to content

Instantly share code, notes, and snippets.

@ChrisMoney
Created August 27, 2015 22:10
Show Gist options
  • Save ChrisMoney/d8f2262fabf0da9e7755 to your computer and use it in GitHub Desktop.
Save ChrisMoney/d8f2262fabf0da9e7755 to your computer and use it in GitHub Desktop.
CLR (Common Runtime Language SQL)
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
public partial class UserDefinedFunctions
{
public const double SALES_TAX = .086;
[SqlFunction()]
public static SqlDouble addTax(SqlDouble originalAmount)
{
SqlDouble taxAmount = originalAmount * SALES_TAX;
return originalAmount + taxAmount;
}
}
// To enable CLR integration, use the clr enabled option of the sp_configure stored procedure with this script.
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'clr enabled', 1;
GO
RECONFIGURE;
GO
// To deploy items in a SQL Server project to a SQL Server:
// 1. Build the project by selecting Build <project name> from the Build menu.
// 2. Select Deploy <project name> from the Build menu.
// Implement CLR in code
SELECT dbo.addTax(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment