怎样将数据类型varchar转换成numeric!!

解决方案 »

  1.   


    cast 或 convert 函数。
      

  2.   

    在VB中用valVal 函数
          返回包含于字符串内的数字,字符串中是一个适当类型的数值。语法Val(string)必要的 string 参数可以是任何有效的字符串表达式.说明Val 函数,在它不能识别为数字的第一个字符上,停止读入字符串。那些被认为是数值的一部分的符号和字符,例如美圆号与逗号,都不能被识别。但是函数可以识别进位制符号 &O(八进制)和 &H(十六进制)。空白、制表符和换行符都从参数中被去掉。下面的返回值为 1615198:Val("    1615 198th Street N.E.")在下面的代码中,Val 为所示的十六进制数值返回十进制数值 -1。Val("&HFFFF")注意 Val 函数只会将句点(.)当成一个可用的小数点分隔符。当使用不同的小数点分隔符时,如在国际版应用程序中,代之以 CDbl 来把字符串转换为数字。
      

  3.   

    CAST and CONVERT (T-SQL)Explicitly converts an expression of one data type to another. CAST and CONVERT provide similar functionality.
    SyntaxUsing CAST:
    CAST(expression AS data_type)
    Using CONVERT:CONVERT (data_type[(length)], expression [, style])ArgumentsexpressionIs any valid Microsoft?SQL Server?expression. For more information, see Expressions. data_typeIs the target system-supplied data type. User-defined data types cannot be used. For more information about available data types, see Data Types. lengthIs an optional parameter of nchar, nvarchar, char, varchar, binary, or varbinary data types. styleIs the style of date format you want when converting datetime or smalldatetime data to character data (nchar, nvarchar, char, varchar, nchar, or nvarchar data types), or the string format when converting float, real, money, or smallmoney data to character data (nchar, nvarchar, char
    , varchar, nchar, or nvarchar data types).
    In the table, the two columns on the left represent the style values for datetime
     or smalldatetime conversion to character data. Add 100 to a style value to get a four-place year that includes the century (yyyy).Without 
    century 
    (yy) With 
    century 
    (yyyy)