You must Sign In to post a response.
  • Category: SQL Server

    Conversion failed when converting the varchar value '%' to data type int.

    Create proc spGetMatchingItem1Id
    @ItemId int

    as
    Begin
    Select ItemId
    from Item1
    where CAST(@ItemId as varchar(10)) like @ItemId + '%'
    end
  • #767506
    The issue clearly showing that there is an issue in the conversion

    Create proc spGetMatchingItem1Id
    @ItemId int

    as
    Begin
    Select ItemId
    from Item1
    where CAST(ItemId as varchar(10)) like CAST(@ItemId as varchar(10)) + '%'
    end

    Try the above code

    By Nathan
    Direction is important than speed

  • #767515
    Hi,

    Problem is this part " like @ItemId + '%'" , you have declare @ItemId as integer type and you are concatenate with varchar "+'%'", syntactically that is wrong, while concatenate both the formats should be in same datatype.

    Any how you are converting into varchar then why can't you declare @ItemId as varchar type?

    If you are Ok with that then refer below sample ex:


    Create proc spGetMatchingItem1Id
    @ItemId Varchar(100)

    as
    Begin
    --your select query
    end


    Hope this will helpful to you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


Sign In to post your comments