

call "C:\Program Files\Microsoft Visual Studio .NET Whidbey\Common7\Tools\vsvars32.bat"
rem compile the assemnbly
csc /target:library FuncProc.cs
rem drop the funcions, if they are there
sqlcmd -d Chapter3 -Q "drop function Same1"
sqlcmd -d Chapter3 -Q "drop function Same2"
sqlcmd -d Chapter3 -Q "drop function AddThese"
sqlcmd -d Chapter3 -Q "drop function AddTheseInt"
sqlcmd -d Chapter3 -Q "drop function Length"
sqlcmd -d Chapter3 -Q "drop function LengthV"
sqlcmd -d Chapter3 -Q "drop function IsTrue"
rem drop the assembly
sqlcmd -d Chapter3 -Q "drop assembly FuncProc"
rem add the assembly as SAFE, first cmd line param is directory of dll
sqlcmd -d Chapter3 -Q "CREATE ASSEMBLY FuncProc FROM '%~1\FuncProc.dll' with PERMISSION_SET = SAFE"
rem add each of the functions
sqlcmd -d Chapter3 -Q "CREATE FUNCTION Same1(@a int) returns int as EXTERNAL NAME FuncProc:[Chapter3.Nulls]::Same1"

sqlcmd -d Chapter3 -Q "CREATE FUNCTION Same2(@a int) returns int as EXTERNAL NAME FuncProc:[Chapter3.Nulls]::Same2"

sqlcmd -d Chapter3 -Q "CREATE FUNCTION AddThese(@a1 int, @2 int) returns int as EXTERNAL NAME FuncProc:[Math.Arithmetic]::AddThese"

sqlcmd -d Chapter3 -Q "CREATE FUNCTION Length(@a1 binary(10)) returns int as EXTERNAL NAME FuncProc:[Math.Arithmetic]::Length"

sqlcmd -d Chapter3 -Q "CREATE FUNCTION LengthV(@a1 varbinary(10)) returns int as EXTERNAL NAME FuncProc:[Math.Arithmetic]::Length"

sqlcmd -d Chapter3 -Q "CREATE FUNCTION AddTheseInt(@a1 int, @2 int) returns int as EXTERNAL NAME FuncProc:[Math.Arithmetic]::AddTheseInt"

sqlcmd -d Chapter3 -Q "CREATE FUNCTION IsTrue(@a1 bit) returns bit as EXTERNAL NAME FuncProc:[Math.Arithmetic]::IsTrue"


rem test the functions just added
sqlcmd -d Chapter3 -Q "print dbo.Same1(1)"
sqlcmd -d Chapter3 -Q "print dbo.Same1(null)"
sqlcmd -d Chapter3 -Q "print dbo.Same2(1)"
sqlcmd -d Chapter3 -Q "print dbo.Same2(null)"
sqlcmd -d Chapter3 -Q "print dbo.Length(0xFFFF)"
sqlcmd -d Chapter3 -Q "print dbo.LengthV(0xFFFF)"




    




