select count(a.newsId) from fs_news as a,fs_news_Class as b,fs_define_save d,fs_define_data e 
where a.classid=b.classid and e.definecolumns=d.dsename and d.dsnewsid=a.newsid  
and ((e.definecolumns='sjstj_other' and cast(dscontent as int) between 23 and 30) 
or (e.definecolumns='sjstj_name' and dscontent ='请选择风格'))dscontent有数字也有文字definecolumns=sjstj_other的是数字
=sjstj_other的是文字
cast(dscontent as int)这一句在e.definecolumns='sjstj_name'的时候也执行还有问一下如果一列有文字,也有数字,不写存储过程和函数,如何获取数字?谢谢

解决方案 »

  1.   

    如何获取数字?ISNUMERIC
    确定表达式是否为一个有效的数字类型。语法
    ISNUMERIC ( expression )参数
    expression要计算的表达式。返回类型
    int注释
    当输入表达式得数为一个有效的整数、浮点数、money 或 decimal 类型,那么 ISNUMERIC 返回 1;否则返回 0。返回值为 1 确保可以将 expression 转换为上述数字类型中的一种。示例
    A. 使用 ISNUMERIC
    下面的示例返回 1,这是因为 zip 列包含有效的数值。 USE pubs
    SELECT ISNUMERIC(zip) 
    FROM authors
    GOB. 使用 ISNUMERIC 和 SUBSTRING
    下面的示例对于 titles 表中的所有书名都返回 0,这是因为没有一个书名是有效的数值。USE pubs
    GO
    -- Because the title column is all character data, expect a result of 0
    -- for the ISNUMERIC function.
    SELECT SUBSTRING(title, 1, 15) type, price, ISNUMERIC(title)
    FROM titles
    GO下面是结果集:type            price                                  
    --------------- -------------------------- ----------- 
    The Busy Execut 19.99                      0           
    Cooking with Co 11.95                      0           
    You Can Combat  2.99                       0           
    Straight Talk A 19.99                      0           
    Silicon Valley  19.99                      0           
    The Gourmet Mic 2.99                       0           
    The Psychology  (null)                     0           
    But Is It User  22.95                      0           
    Secrets of Sili 20.00                      0           
    Net Etiquette   (null)                     0           
    Computer Phobic 21.59                      0           
    Is Anger the En 10.95                      0           
    Life Without Fe 7.00                       0           
    Prolonged Data  19.99                      0           
    Emotional Secur 7.99                       0           
    Onions, Leeks,  20.95                      0           
    Fifty Years in  11.95                      0           
    Sushi, Anyone?  14.99                      0           (18 row(s) affected)
      

  2.   

    估计是我表达不清吧,我是想获取这一列的数字,转为int类型,原来为nvarchar
      

  3.   

    不是已经告诉你了吗?ISNUMERIC(列名) = 1
      

  4.   

    --提取数字
    IF OBJECT_ID('DBO.GET_NUMBER2') IS NOT NULL
    DROP FUNCTION DBO.GET_NUMBER2
    GO
    CREATE FUNCTION DBO.GET_NUMBER2(@S VARCHAR(100))
    RETURNS VARCHAR(100)
    AS
    BEGIN
    WHILE PATINDEX('%[^0-9]%',@S) > 0
    BEGIN
    set @s=stuff(@s,patindex('%[^0-9]%',@s),1,'')
    END
    RETURN @S
    END
    GO
    --测试
    PRINT DBO.GET_NUMBER('呵呵ABC123ABC')
    GO
    --123
      

  5.   

    select case
     when then isnumberic(test)=1 then 
      cast(test as int) else 'null' end test_num 
     from tb_name
      

  6.   

    ISNUMERIC(列名) = 1 and cast(列名 as int) between 2 and 5
      

  7.   


    马上结贴,THANK………………
      

  8.   

    呵呵,再问个问题
     ((e.definecolumns='sjstj_other' and cast(dscontent as int) between 23 and 30)  
    or (e.definecolumns='sjstj_name' and dscontent ='请选择风格'))
    中间使用or连接的,为什么符合e.definecolumns='sjstj_name'条件的也会去cast(dscontent as int)里面呢?