gpt4 book ai didi

sql - 当列的数据类型为 int 时如何用字符串替换 null

转载 作者:行者123 更新时间:2023-12-04 20:56:17 25 4
gpt4 key购买 nike

我有一个包含 3 列的表格和如下示例数据:

enter image description here

所有列的数据类型都是int

我有这个问题:

select 
foodid, dayid
from
Schedule

如果 dayid=null ,我想用字符串替换 dayid

为此,我尝试了这个查询:

select 
foodid,
Dayid + ISNULL(dayid,'not day')
from Schedule

但我收到了这个错误:

Conversion failed when converting the varchar value 'not day' to data type int.

如何做到这一点?

最佳答案

请试试这个:

select foodid, ISNULL(str(dayid),'not day') from Schedule

关于sql - 当列的数据类型为 int 时如何用字符串替换 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28795668/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com