USE [p2j_test]
GO

/****** Object:  SqlAssembly [TestAssembly]    Script Date: 2/21/2014 5:55:44 PM ******/
DROP ASSEMBLY [TestAssembly]

GO

/****** Object:  SqlAssembly [TestAssembly]    Script Date: 2/21/2014 5:55:44 PM ******/
CREATE ASSEMBLY [TestAssembly]
FROM 0x[encoded data, 9216 characters]
WITH PERMISSION_SET = SAFE

GO

CREATE FUNCTION [dbo].[CSharpAdd]
   (@param1 BIGINT, @param2 BIGINT)
   RETURNS BIGINT
   AS EXTERNAL NAME TestAssembly.Functions.CSharp_Add_Int64

CREATE FUNCTION [dbo].[CSharpDouble]
   (@param1 BIGINT)
   RETURNS BIGINT
   AS EXTERNAL NAME TestAssembly2.Functions2.CSharp_Double_Int64

CREATE FUNCTION [dbo].[CSharpConcat]
   (@param1 NVARCHAR(2000), @param2 NVARCHAR(2000))
   RETURNS NVARCHAR(4000)
   AS EXTERNAL NAME TestAssembly.Functions.CSharp_Add_String


CREATE FUNCTION [dbo].[CSharpConcat2]
   (@param1 NVARCHAR(2000))
   RETURNS NVARCHAR(4000)
   AS EXTERNAL NAME TestAssembly2.Functions2.CSharp_Double_String


-- creates a functions that adds two int64
-- th3 function delegates to Operators.P2J_Add from p2j_operators.dll
CREATE FUNCTION [dbo].[ClrScalarFn_Add]
   (@param1 BIGINT, @param2 BIGINT)
   RETURNS BIGINT
   AS EXTERNAL NAME p2j_operators.Operators.P2J_Add


select [dbo].[CSharpAdd](0, -1)
select [dbo].[CSharpConcat]('12', '34')
select [dbo].[CSharpDouble](5)
select [dbo].[CSharpConcat2]('10')


SET IDENTITY_INSERT [book] ON
SET IDENTITY_INSERT [book].id ON
insert into [book] values ('oo8', 8, 'mii')
select * from [book]
select * from sys.assembly_files



-- enabling execution oc CLR code on SQL server:
EXEC sp_configure 'clr enabled';
EXEC sp_configure 'clr enabled' , '1';
RECONFIGURE;


EXEC  sp_addextendedproc 'CSharp_Add_Int64', 'c:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\Binn\p2j_operators.dll';

select Operators.P2J_Add(2, 2)


