SQL查询,如果值为空则返回1 [英] SQL query, if value is null then return 1

查看:98
本文介绍了SQL查询,如果值为空则返回1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个查询返回我们系统中设置的汇率值.并非每个订单都有汇率 (currate.currentrate),因此它返回空值.

I have a query that is returning the exchange rate value set up in our system. Not every order will have an exchange rate (currate.currentrate) so it is returning null values.

我可以让它返回 1 而不是 null 吗?

Can I get it to return 1 instead of null?

可能类似于 if 语句:

Something like an if statement maybe:

 if isnull(currate.currentrate) then 1 else currate.currentrate 

下面是我的查询.我非常感谢您的所有帮助!

Here is my query below. I greatly appreciate all your help!

 SELECT     orderhed.ordernum, orderhed.orderdate, currrate.currencycode,  currrate.currentrate
 FROM         orderhed LEFT OUTER JOIN
                  currrate ON orderhed.company = currrate.company AND orderhed.orderdate = currrate.effectivedate

推荐答案

您可以使用 CASE 语句.

SELECT 
    CASE WHEN currate.currentrate IS NULL THEN 1 ELSE currate.currentrate END
FROM ...

这篇关于SQL查询,如果值为空则返回1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆