Conversion failed when converting the varchar value 'default.asp?ID =' to data type int.


I'm getting the following error --

Conversion failed when converting the varchar value 'default.asp?ID =' to data type int.

my code is --

CASE WHEN P.Title <> '' THEN P.Title ELSE N.Title END as Title,
CASE WHEN P.ID <> '' THEN 'default.asp?ID ='+P.ID+'&amp='+P.SEOLink ELSE N.AlternativeURL END as URL
from [dbo].[MYNavigation] N
LEFT Join dbo.MyPage P
on N.PageID = P.ID
Where N.Live = 'Y'
Order By NavOrder

Open in new window

Thank you
Who is Participating?
DustinKikuchiConnect With a Mentor Commented:
Without seeing your table structure I'm going to guess that P.ID is an INT field and your query is attempting to add your string mathematically rather that concatenate as your are trying to do.  If this is the case, you may need to CAST(P.ID AS varchar(<appropriateLength>) in your statement to perform the concatenation.

Just my initial thought upon seeing the query.
Paul MacDonaldDirector, Information SystemsCommented:
I just wanted to jump in and say you should be using parameterized queries. Unless you're doing some sort of manual examination, your SQL there is ripe for exploitation.  You will be hacked - it's just a matter of time.
garethtnashAuthor Commented:
Thank you
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.