Click here to Skip to main content
15,668,923 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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.
Posted

1 solution

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

SQL
ELSE 'Some URL' + CONVERT(NVARCHAR(10), FotoId) + '-100-100-9.jpg'
 
Share this answer
 
Comments
willempipi 24-Apr-12 4:06am    
I hate SQL
OriginalGriff 24-Apr-12 4:10am    
It's error messages could use a good kicking, I admit!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900