Writing Database Objects in CLR: Advanced Scenarios

Monday Sep 26th 2005 by DatabaseJournal.com Staff
Share:

When you write code to be run inside SQL Server 2005, you usually want to deal with other database objects. Learn how to write a CLR-stored procedure that uses a simple table valued function to handle that scenario in a couple of ways.

[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

Share:
Home
Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved