select * from book where price = x这里的x判断它是否包含数字也就是说,在书表中,有的价格是数字,有的价格还包含了中文字符,而有的是纯粹的中文字符,例如:“价格面议”。我想只查询带数字的价格,“价格面议”之类的中文字符就不显示了。

解决方案 »

  1.   

    select * from book where price = CASE WHEN ISNUMERIC(x)=1 THEN CAST(X AS NUMERIC(10,2) ELSE -1 END
      

  2.   

    select * from book where charindex('0',price) or charindex('1',price)....or charindex('9',price)
      

  3.   

    好像应该:
    select * from book where CASE WHEN ISNUMERIC(price)=1 THEN CAST(price AS NUMERIC(10,2) ELSE -1 END=X
    我想只查询带数字的价格,“价格面议”之类的中文字符就不显示了。select * from book where ISNUMERIC(price)=1
      

  4.   

    ISNUMERIC
    确定表达式是否为一个有效的数字类型。语法
    ISNUMERIC ( expression )参数
    expression要计算的表达式。返回类型
    int注释
    当输入表达式得数为一个有效的整数、浮点数、money 或 decimal 类型,那么 ISNUMERIC 返回 1;否则返回 0。返回值为 1 确保可以将 expression 转换为上述数字类型中的一种。
      

  5.   

    select * from book where isnumeric(price) = 1
      

  6.   

    select * from book where price like '[0-9]'
      

  7.   

    select Price from book
    where charindex('0',Price) or
    charindex('1',Price) or
    charindex('2',Price) or
    charindex('3',Price) or
    charindex('4',Price) or
    charindex('5',Price) or
    charindex('6',Price) or
    charindex('7',Price) or
    charindex('8',Price) or
    charindex('9',Price)服务器: 消息 156,级别 15,状态 1,行 2
    在关键字 'or' 附近有语法错误。
      

  8.   

    select * from book where price like '[0-9]'
    只显示出了'0','1'
      

  9.   

    declare @ta table(id varchar(20))
    insert @ta 
    select 123123564564 union all
    select '中国人万岁' union all
    select 'adfadfa1213'union all
    select 15.6select * from @ta where isnumeric(id)=1select * from @ta where id not like '%[^.0-9]%'
    (所影响的行数为 4 行)id                   
    -------------------- 
    123123564564
    15.6(所影响的行数为 2 行)
      

  10.   

    declare @ta table(id varchar(20))
    insert @ta 
    select 123123564564 union all
    select '中国人万岁' union all
    select 'adfadfa1213'union all
    select 15.6
    select * from @ta where id   like '%[0-9]%'(所影响的行数为 4 行)id                   
    -------------------- 
    123123564564
    adfadfa1213
    15.6(所影响的行数为 3 行)这是查询字段有数字的字段,如果只显示字段中的数字,要写一个函数才行
      

  11.   

    declare @str nvarchar(300)
    set @str = N'dafjzdnldnmfads$'
    select case when patindex('%[0-9,$,¥]%',@str)>0 then '包含' else '不包含' end