sql 中 case 条件的替代选项

发布于 2024-12-25 19:57:49 字数 386 浏览 2 评论 0原文

如何检查列值是否为零

我想插入 50 个列值,每一列我想检查该值是否为 0。如果值为 0,那么它应该为 null

查询

insert into table1 values (Case when column1 = '0' then null else column1 end, .....
Case when column50 = '0' then null else column50 end)

上面的查询正在工作,但是查询长度太长,因为我正在使用上面的 50 列查询,

有任何替代选项可以检查列值是否为 0。

像这样 if(column1, 0) then null

需要查询帮助

How to check the column value zero or not

I want to insert 50 column values, each column i want to check whethere the value is 0 or not. If the value is 0 then it should be null

Query

insert into table1 values (Case when column1 = '0' then null else column1 end, .....
Case when column50 = '0' then null else column50 end)

The above query is working, but query length is too long because i am using the above query of 50 column's

there is any alternative option is there for check the column value is 0 or not.

like this if(column1, 0) then null

Need Query Help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

江南月 2025-01-01 19:57:49

尝试使用 NULLIF

insert into table1 values (NULLIF(column1, '0'), .....
NULLIF(column50, '0'))

Try using NULLIF:

insert into table1 values (NULLIF(column1, '0'), .....
NULLIF(column50, '0'))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文