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

Posted on 2012-08-14
Last Modified: 2012-08-14

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
Question by:garethtnash
    LVL 33

    Expert Comment

    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.
    LVL 4

    Accepted Solution

    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.

    Author Closing Comment

    Thank you

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
    Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
    Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now