基本的SQL问题(将varchar值"转换为int数据类型时,转换失败.) [英] Basic SQL problem (Conversion failed when converting the varchar value '' to data type int.)

查看:124
本文介绍了基本的SQL问题(将varchar值"转换为int数据类型时,转换失败.)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试使此查询非常简单,但与我和SQL一样,它始终不起作用.

Hi,

I''m trying to get this fairly easy query to work but, as always with me and SQL, it doesn''t work.

(
SELECT 
   (
      CASE WHEN FotoId IS NULL 
      THEN ''Some URL''
      ELSE ''Some URL'' + FotoId + ''-100-100-9.jpg''
      END
   ) AS FotoURL
FROM Fotos
WHERE ProfielId = 123



错误:



ERROR:

Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value ''Some URL'' to data type int.

推荐答案

这是因为您试图连接字符串和整数-您需要将整数转换为字符串:

It''s because you are trying to concatenate a string and an int - you need to convert the int to a string:

ELSE 'Some URL' + CONVERT(NVARCHAR(10), FotoId) + '-100-100-9.jpg'


这篇关于基本的SQL问题(将varchar值"转换为int数据类型时,转换失败.)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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