Writing Database Objects in CLR: Advanced Scenarios

September 26, 2005

[From Developer.com]

My previous article demonstrated how to write a simple table valued function (TVF) that accepts an integer and returns a table of results, breaking down the input of value into its factors. Thus, if you pass in 2, you get 1 and 2, but if you pass in 15, you get 1, 3, 5, and 15.

But you may ask, 'what does that have to do with a database?' It turns out—not much. And when you write code to be run inside SQL Server 2005, more often than not, you will want to deal with other database objects, much in the same way T-SQL would.

This article carries the discussion forward by writing another object: a CLR-stored procedure that uses the TVF written in the previous article. This stored procedure will accept a positive integer and return all prime numbers less than the input. A prime number is a number that is divisible by 1 and itself, so you easily could use the TVF, find the number of factors, and return the numbers that qualify as prime numbers.

The article continues at http://www.developer.com/net/net/article.php/3550341








The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers