Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Comma Delimit Problem

I have a small problem. I am getting this error, and I would appreciate if anyone could help me out! All I am trying to do is a comma delimited list.

SET NOCOUNT ON;

DECLARE @TypeID Varchar(250)

SELECT
    @TypeID = COALESCE(@TypeID +',' ,'') + TypeID 
FROM
    Related

RETURN @TypeID 

Conversion failed when converting the varchar value '8,' to data type int.

Does anyone know how to fix, please? I've tried CONVERT(VARCHAR, @TypeID) but this doesn't seem to make any difference!

like image 682
techco1 Avatar asked May 03 '26 14:05

techco1


1 Answers

Is the field TypeId in the related table an integer? You would need to cast the database field to a varchar for your code to work

Select @typeId = coalesce(@typeId+',','') + cast(typeId as varchar(20))
from related
like image 77
Sparky Avatar answered May 05 '26 08:05

Sparky