Skip to content
Advertisement

Error converting data type varchar to bigint when trying to concatenate column row values

I have the following query that I am using to concatenate the row values of a column into a single value.

The id_number column is of type varchar. I have tried to convert to text but still getting errors.

Advertisement

Answer

id_number is a bigint, you’ll need to CONVERT or CAST it to a text type:

If you’re using SQL Server 2017 or later you can use STRING_AGG (MS SQL Server’s equivalent to MySQL’s GROUP_CONCAT):

(SQL Server will handle the implicit bigint-to-varchar conversion for you as there’s no ambiguousness introduced by the use of binary operators).

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement