gpt4 book ai didi

sql - SQL如果可能,将值转换为int,如果不可能,则将值设置为0

转载 作者:行者123 更新时间:2023-12-02 09:06:18 25 4
gpt4 key购买 nike

需要Sql查询,如果可能,将值转换为int,如果不可能,则将value设置为0。

SELECT IIF((isnumeric('11961630')),TRY_PARSE('11961630' as int), 0) => it should return 11961630
SELECT IIF((isnumeric('CH11961630')),TRY_PARSE('CH11961630' as int), 0) => it should return 0

最佳答案

select isnull(try_parse('42' as int), 0) -- returns 42
select isnull(try_parse('fred' as int), 0) -- returns 0

关于sql - SQL如果可能,将值转换为int,如果不可能,则将值设置为0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58029544/

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