表中有一个字段,类型为NVARCHAR
里面有的值为时间,如2008-01-01
现在的问题是,我要作一个时间比较
但是首先要判断这个值是否可以转换为时间
也不知道是否表达清楚了
下面的语句,会出错的,因为有的值不能转换为时间格式
SELECT  *
FROM         SelectFile
WHERE     dscontent='测试' and cast(dscontent as datetime)>getdate()如何比较之前先判断一下呢,感谢大家

解决方案 »

  1.   

    SELECT  *
    FROM  SelectFile
    WHERE ISDATE(dscontent)=1
        AND dscontent='测试' 
        and cast(dscontent as datetime)>getdate()
      

  2.   

    SELECT *
    FROM SelectFile
    where ISDATE(dscontent)=1
    and dscontent='测试' and cast(dscontent as datetime)>getdate()
      

  3.   


    SELECT *
    FROM SelectFile
    where ISDATE(dscontent)=1
    and dscontent='测试' and cast(dscontent as datetime)>getdate()
      

  4.   


    dscontent='测试' and cast(dscontent as datetime)>getdate()这样的条件好像满足不了吧!
      

  5.   


    SELECT *
    FROM SelectFile
    where ISDATE(dscontent)=1
    and dscontent='测试' and cast(dscontent as datetime)>getdate()
      

  6.   


    SELECT  *
    FROM SelectFile
    WHERE  dscontent='测试' and cast(dscontent as datetime)>getdate() and isdate(dscontent)=1