Concatenating int and nvarchar column in TSQL
are you sure the error is related to the casts and not to the where conditions? check that the column types are matching
i think this'll do :
SELECT (CONVERT(NVARCHAR, GotoviProizvodi.ID) + ' - ' + GotoviProizvodi.Opis) AS Opis FROM GotoviProizvodi,Recept WHERE [email protected] AND Recept.Proizvod=GotoviProizvodi.Opis
Related videos on Youtube
07 : 16
SQL Query | Split Concatenated String into Columns | CharIndex
00 : 32
How to CHANGE COLUMN TYPE VARCHAR to INT in SQL
00 : 40
How to CHANGE COLUMN TYPE INT to VARCHAR in SQL
02 : 23
How to get the Max Disk Space consumed by a NVARCHAR column in SQL Server.
10 : 30
CONCAT() function in SQL Server 2012
03 : 10
SQL Concatenate - SQL Training Online - Quick Tips Ep15
10 : 23
How to Concatenate String Values with Integer values in SQL Server - TSQL Tutorial
03 : 21
SQL Server - Concatenate rows into a string
05 : 40
How to concatenate text from multiple rows into a single text string in SQL server?
02 : 30
SQL Concat Function in SQL Server - SQL Training Online - Quick Tips Ep48
11 : 50
Joining strings in SQL Server: +, CONCAT, CONCAT_WS and STRING_AGG
Kiro ConeskiUpdated on June 14, 2022
Kiro Coneski 12 months
I'm using MSSQL EXPRESS 2008 and I'm trying to concatenate the record's ID column with it's description column using the following query
SELECT CAST(GotoviProizvodi.ID as nvarchar(4)) + ' - ' + CAST(GotoviProizvodi.Opis as nvarchar(max)) AS Opis FROM GotoviProizvodi,Recept WHERE [email protected] AND Recept.Proizvod=GotoviProizvodi.Opis GotoviProizvodi.ID is defined in the schema as int -- the ID column GotoviProizvodi.Opis is defined as nvarchar(200) -- the description column
But, when I try to execute the query it yields this:
Msg 245, Level 16, State 1, Procedure GetProizvodByReceptId, Line 2 Conversion failed when converting the nvarchar value 'Test' to data type int.
Why is it trying to convert it into int, when I'm explicitly telling it to convert it into nvarchar? Any workarounds?
Taryn over 10 yearswhat is the datatype of
Recept.Proizvodon the join?
Kiro Coneski over 10 yearsYou're right. It should have been Recept.Proizvod=GotoviProizvodi.ID.
Critical issues have been reported with the following SDK versions: com.google.android.gms:play-services-safetynet:17.0.0