Error converting bigint data type to varchar.

DECLARE @ID BIGINT
set @ID = 1323
UPDATE School 
SET RegistrationFee = 'fee_' + @ID --<<<<error 
Where SchoolRegistrationId = 123

Error converting varchar data type to bigint.

+3
source share
3 answers

You need to explicitly convert bigint to varchar:

DECLARE @ID BIGINT
set @ID = 1323

UPDATE School 
SET RegistrationFee = 'fee_' + CAST(@ID AS VARCHAR(15)) 
WHERE SchoolRegistrationId = 123

T-SQL will not do this automatically for you - you need to be explicit and understandable.

+8
source

You cannot concatenate a string into a number. You must convert it:

SET RegistrationFee = 'fee_' + LTRIM(STR(@ID))

+4
source

SQL Server . . script diffirent (varchar bigint). Bigint - . " , , , (+) (-). . , 123 456,00, ." (. https://docs.microsoft.com/en-us/sql/t-sql/data-types/data-type-conversion-database-engine.)

. . , CAST.

RegistrationFee .

'fee_' + CAST(@ID AS NVARCHAR(25)) 
'fee_' + CAST(@ID AS VARCHAR(25)) 
'fee_' + CAST(@ID AS CHAR(25)) 
'fee_' + CAST(@ID AS NCHAR(25)) 

- Bigint's maximum value is "9,223,372,036,854,775,807", which has 25 characters.

+1
source

Source: https://habr.com/ru/post/1795579/


All Articles