Maybe I will write an FAQ's. Do you have visual studio 2005 or just BIDS?
I think you need the full version of VS (maybe pro even).
Anyway, here goes
1. Open Visual Studio, click 'Create Project'
2. Under Visual Basic and C#, there are project types available called 'Database Project'
3. Choose Database Project, then select 'SQL Server Project', name your project and create it (these are stored in the same folder as your regular VS Projects, so I always start the name with clr so I know what I'm looking for).
4. Click Project --> Add User-Defined Function
5. Paste in the code (if you are using C#, need to rewrite if you want to do it with VB of course) into your new .cs file.
6. Build --> Deploy
7. Run this code to enable CLR (or you won't be able to use it)
Code:
EXEC sp_configure 'show advanced options' , '1';
go
reconfigure;
go
EXEC sp_configure 'clr enabled' , '1'
go
reconfigure;
-- Turn advanced options back off
EXEC sp_configure 'show advanced options' , '1';
go
8. Script your resulting function as an alter, to change parameter types to nvarchar(max) and nvarchar(something < max), respectively. I don't know why the default size for a string once you deploy is nvarchar(4000). It will look like this after you make the changes:
Code:
ALTER FUNCTION [dbo].[clrSplit](@toSplit [nvarchar](max), @delimiter [nvarchar](15))
RETURNS TABLE (
[ID] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) WITH EXECUTE AS CALLER
AS
EXTERNAL NAME [SqlServerProject1].[UserDefinedFunctions].[Split]
GO
EXEC sys.sp_addextendedproperty @name=N'AutoDeployed', @value=N'yes' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'FUNCTION', @level1name=N'clrSplit'
GO
EXEC sys.sp_addextendedproperty @name=N'SqlAssemblyFile', @value=N'clrSplit.cs' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'FUNCTION', @level1name=N'clrSplit'
GO
EXEC sys.sp_addextendedproperty @name=N'SqlAssemblyFileLine', @value=10 ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'FUNCTION', @level1name=N'clrSplit'
Then after this, you are ready to try it (you can try before altering the function, but it will not return any characters past 4000.
use it like a normal table valued function.
Hope it helps,
Alex
Ignorance of certain subjects is a great part of wisdom