例如:
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([EID] varchar(2),[OID] varchar(2))
insert [tb]
select 'E1','abc' union all
select 'E2','348' union all
select 'E3','dddd' union all
select 'E4','23' union all
select 'E5','341' union all
select 'E6','afdfa'统计第二列中是数字的字段,可以统计吗,怎么统计,谢谢先

解决方案 »

  1.   

    if object_id('[tb]') is not null drop table [tb]
    go
    create table [tb]([EID] varchar(2),[OID] varchar(8))
    insert [tb]
    select 'E1','abc' union all
    select 'E2','348' union all
    select 'E3','dddd' union all
    select 'E4','23' union all
    select 'E5','341' union all
    select 'E6','afdfa'select SUM(isnumeric(oid)) from tb
    /*
    -----------
    3(1 行受影响)
    */
      

  2.   

    if object_id('[tb]') is not null drop table [tb]
    go
    create table [tb]([EID] varchar(2),[OID] varchar(8))
    insert [tb]
    select 'E1','abc' union all
    select 'E2','348' union all
    select 'E3','dddd' union all
    select 'E4','23' union all
    select 'E5','341' union all
    select 'E6','afdfa'select *,是否数字=case isnumeric(oid) when 1 then '是' else '否' end from tb
    /*
    EID  OID      是否数字
    ---- -------- ----
    E1   abc      否
    E2   348      是
    E3   dddd     否
    E4   23       是
    E5   341      是
    E6   afdfa    否(6 行受影响)*/
      

  3.   

    if object_id('[tb]') is not null drop table [tb]
    go
    create table [tb]([EID] varchar(2),[OID] varchar(5))
    insert [tb]
    select 'E1','abc' union all
    select 'E2','348' union all
    select 'E3','dddd' union all
    select 'E4','23' union all
    select 'E5','341' union all
    select 'E6','afdfa'select * from tb where isnumeric([OID])=1
    /*
    EID  OID
    ---- -----
    E2   348
    E4   23
    E5   341(3 行受影响)
    */
      

  4.   

    --------------IsNumeric--------------
    IsNumeric 函数
    返回 Boolean 值,指出表达式的运算结果是否为数。语法IsNumeric(expression)必要的 expression 参数是一个 Variant,包含数值表达式或字符串表达式。说明如果整个 expression 的运算结果为数字,则 IsNumeric 返回 True;否则返回 False。如果 expression 是日期表达式,则 IsNumeric 返回 False。
      使用该函数时候应该注意这样一些问题:
      举例:  
      "123"  
      "123.1"  
      "123,,,,111.222,,,333"  
      "123,,,1.22,,,3"  
      "123e+9"  
      "123d-8"  
      以上返回的都是True  
      第1、2条很正常,  
      第三条有西文的",",可以理解:外国人习惯把数字隔3个加个逗号。  
      第四条中文的","也可以,可要注意:  
      cint("12,,3")可以得到123  
      cint("12,,3")就出错了 
      第四第五条,里面有"e","d","+","-",应该不是数字,但是这里是科学计数法。所以当是数字。