Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Text,query,text+query+text

Need help

Msg 245, Level 16, State 1, Line 9
Conversion failed when converting the varchar value '404-Nivelacija MPC - ' to data type int.


What I have tried:

INSERT into dbo.trgovacka_knjiga (redni_broj, broj_dokumenta, opis) 
VALUES (1, (select max (redni_broj) from dbo.nivelacije_lista), '404-Nivelacija MPC - '+ (select max(redni_broj) from dbo.nivelacije_lista) +' / 2019')
Posted
Updated 12-Jul-19 23:07pm
Comments
Goran Bibic 13-Jul-19 5:02am    
This is type work

'404-Nivelacija MPC - " + redni_brojListaTextBox.Text + "/" + DateTime.Now.Year + "'

This is type I need

'404-Nivelacija MPC - " + (select max(redni_broj) from dbo.nivelacije_lista) + "/" + DateTime.Now.Year + "'

1 solution

You are trying to concatenate a string with an int:
SQL
'404-Nivelacija MPC - '+ (select max(redni_broj) from dbo.nivelacije_lista) +' / 2019'
So SQL is trying to be helpful and convert the first string to an integer so it can add the two numbers together.
Tell SQL "these are all strings" and it will work fine:
SQL
CONCAT('404-Nivelacija MPC - ', (select max(redni_broj) from dbo.nivelacije_lista), ' / 2019')
 
Share this answer
 
Comments
Goran Bibic 13-Jul-19 5:18am    
Thank you
OriginalGriff 13-Jul-19 5:25am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900