Check if field is numeric, then execute comparison on only those field in one statement?

后端 未结 3 978
春和景丽
春和景丽 2021-01-17 10:05

This may be simple, but I am no SQL whiz so I am getting lost. I understand that sql takes your query and executes it in a certain order, which I believe is why this query d

相关标签:
3条回答
  • 2021-01-17 11:02

    try this:

    select * from purchaseorders
    where try_cast(purchase_order_number as int) >= 7
    
    0 讨论(0)
  • 2021-01-17 11:03

    does this work for you?

    select * from purchaseorders
    where (case when IsNumeric(purchase_order_number) = 1
           then cast(purchase_order_number as int)
           else 0 end) >= 7
    
    0 讨论(0)
  • 2021-01-17 11:08

    You can do a select with a subselect

    select * from (
    select * from purchaseorders
    where IsNumeric(purchase_order_number) = 1) as correct_orders
    where cast(purchase_order_number as int) >= 7
    
    0 讨论(0)
提交回复
热议问题