Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Conversion failed when converting the varchar value in SQLSERVER 2008

Conversion failed when converting the varchar value in SQLSERVER 2008

Scheduled Pinned Locked Moved Database
databasehelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    ChandrakanthGaddam
    wrote on last edited by
    #1

    Hi this is Chandra. i have one issue with Sql Stored procedure. Please find the query below. declare @Measure varchar(50) declare @Time varchar(50) declare @Manufacturer varchar(50) declare @CategoryID int SET @Measure ='Value' SET @Time ='4 Weeks&' SET @Manufacturer ='Jti Gallaher Ltd' SET @CategoryID = 377; Declare @SELECTtQuery1 varchar(1000) Declare @FromQuery1 varchar(1000) Declare @GROUPBYQuery1 varchar(1000) Declare @SQLQuery AS NVarchar(4000) Declare @ParamDefinition AS NVarchar(2000) SET @FromQuery1 = 'FROM [dbo].[iView_Data_TCG_Aggregated_Product] WHERE PeriodName = '''+@Time+''' AND Manufacturer = '''+@Manufacturer+''' AND CategoryId = '''+ @CategoryID+ print @FromQuery1 When i execute this query i am getting the conversion error. PLease find the error below. ---------------------- Conversion failed when converting the varchar value ' FROM [dbo].[iView_Data_TCG_Aggregated_Product] WHERE PeriodName = '4 Weeks' AND Manufacturer = 'Test1' AND CategoryId = '' to data type int. ---------------------------------------------- I am not getting categoryid value when i execute. It is giving error. Please suggest me wht to do. Thanks Chandrakanth

    S 1 Reply Last reply
    0
    • C ChandrakanthGaddam

      Hi this is Chandra. i have one issue with Sql Stored procedure. Please find the query below. declare @Measure varchar(50) declare @Time varchar(50) declare @Manufacturer varchar(50) declare @CategoryID int SET @Measure ='Value' SET @Time ='4 Weeks&' SET @Manufacturer ='Jti Gallaher Ltd' SET @CategoryID = 377; Declare @SELECTtQuery1 varchar(1000) Declare @FromQuery1 varchar(1000) Declare @GROUPBYQuery1 varchar(1000) Declare @SQLQuery AS NVarchar(4000) Declare @ParamDefinition AS NVarchar(2000) SET @FromQuery1 = 'FROM [dbo].[iView_Data_TCG_Aggregated_Product] WHERE PeriodName = '''+@Time+''' AND Manufacturer = '''+@Manufacturer+''' AND CategoryId = '''+ @CategoryID+ print @FromQuery1 When i execute this query i am getting the conversion error. PLease find the error below. ---------------------- Conversion failed when converting the varchar value ' FROM [dbo].[iView_Data_TCG_Aggregated_Product] WHERE PeriodName = '4 Weeks' AND Manufacturer = 'Test1' AND CategoryId = '' to data type int. ---------------------------------------------- I am not getting categoryid value when i execute. It is giving error. Please suggest me wht to do. Thanks Chandrakanth

      S Offline
      S Offline
      scottgp
      wrote on last edited by
      #2

      A few things: - Since you're concatenating things together, @CategoryID will have to be converted to a string. Otherwise, SQL Server is trying to perform addition and convert the first variables to an int. Try changing the SET to this:

      SET @FromQuery1 = 'FROM [dbo].[iView_Data_TCG_Aggregated_Product]
      WHERE PeriodName = '''+@Time+'''
      AND Manufacturer = '''+@Manufacturer+''' AND CategoryId = '''+ cast(@CategoryID as varchar(10))

      - There was a dangling plus sign I removed from what you posted just to get it to execute - If this is going to be a valid query, your'e missing the SELECT clause with the columns to select. Scott

      C 1 Reply Last reply
      0
      • S scottgp

        A few things: - Since you're concatenating things together, @CategoryID will have to be converted to a string. Otherwise, SQL Server is trying to perform addition and convert the first variables to an int. Try changing the SET to this:

        SET @FromQuery1 = 'FROM [dbo].[iView_Data_TCG_Aggregated_Product]
        WHERE PeriodName = '''+@Time+'''
        AND Manufacturer = '''+@Manufacturer+''' AND CategoryId = '''+ cast(@CategoryID as varchar(10))

        - There was a dangling plus sign I removed from what you posted just to get it to execute - If this is going to be a valid query, your'e missing the SELECT clause with the columns to select. Scott

        C Offline
        C Offline
        ChandrakanthGaddam
        wrote on last edited by
        #3

        Hi Scott,Thanks and lot. I got it. It is working fine from my end . Thanks Chandra

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups