CLR for sql server 2005

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aas4mis
    New Member
    • Jan 2008
    • 97

    CLR for sql server 2005

    I know this is C#, but thought the SQL community would know better. I'm trying to get a CLR compiled to handle a Double.TryParse () via TSQL and the code won't compile.

    I'm no C# guru, found this code on the web when looking for a way to try_parse in earlier versions of sql (2005).

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data.SqlTypes;
    using Microsoft.SqlServer.Server;
    
    namespace ClassLibrary1
    {
        public class Class1
        {
            [SqlFunction]
            public static SqlDouble TryParseDouble(SqlString str) 
            { 
                    Double d; 
                    bool success = [U]Double.TryParse(str, out d)[/U]; 
                    if (!success)     
                           return SqlDouble.Null; 
                    return new SqlDouble(d); 
            } 
        }
    }
    The underlined is where my issue is. Here is the error.

    Code:
    Error	1	The best overloaded method match for 'double.TryParse(string, out double)' has some invalid arguments	c:\xxxxx\Class1.cs	16	32	ClassLibrary1
    Error	2	Argument 1: cannot convert from 'System.Data.SqlTypes.SqlString' to 'string'	c:\xxxxx\Class1.cs	16	48	ClassLibrary1
    Any help on the matter would be appreciated, i'm ready for an easier way to convert varchar to decimal(18,8) and not break on errors to be expected.

    Thanks!
  • aas4mis
    New Member
    • Jan 2008
    • 97

    #2
    Nevermind.. :) Looks like the 'str' inside of the Double.TryParse () needed to be 'str.Value'. I'll load this into sql and post back if it works.

    Thanks!

    (you know, it's bad enough to talk to ones self, but to answer ones self??).. Programmers

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      Why not use the ISNUMERIC() function that's available in T-SQL?

      Comment

      Working...