David McAfee
davidmcafee at gmail.com
Wed Mar 7 12:10:43 CST 2012
I didn't have a chance to look at your code, but this is something I have used in the past: ALTER FUNCTION dbo.isPrime (@i INT) RETURNS BIT AS BEGIN DECLARE @b BIT DECLARE @n INT SET @b=1 SET @n=@i-1 WHILE (@n>1) BEGIN IF @i%@n = 0 BEGIN SET @b=0 SET @n=1 END SET @n=@n-1 END RETURN @b END GO /* Call in this manner: SELECT dbo.isPrime (1), dbo.isPrime (2), dbo.isPrime (17), dbo.isPrime (21), dbo.isPrime (23), dbo.isPrime (1021) */ On Fri, Oct 28, 2011 at 11:30 AM, Alan Lawhon <lawhonac at hiwaay.net> wrote: > I'm almost embarrassed to post this, but after two days of trying to debug > this, I'm near the screaming point. (Ha! Ha! I know . real programmers > don't scream, but I'm new to SQL Server 2008R2 - Express Edition, so I'm > experiencing routine growing pains.) >