What's happening? Remember that + means both addition and concatenation of strings. It so happened that - can be interpreted as a number (for example, -0 ), so SQL Server prefers to interpret + as an addition.
Usually, when you perform this type of operation, the separation character cannot be interpreted as a number, and you just get an error message. It surprises me that in this case you will not get an error.
One method is to explicitly enter values ββas strings:
SELECT CAST(CID as VARCHAR(255)) + '-' + CAST(RID + as VARCHAR(255)) '-'+ CAST(CGID as VARCHAR(255)) As [IdCombination]
In SQL Server 2012+, you can make it simpler using CONCAT() :
SELECT CONCAT(CID, '-', RID, '-', 'CGID) As [IdCombination]
CONCAT() knows that everything should be a string.
source share