473,424 Members | 2,000 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,424 software developers and data experts.

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

This is driving me crazy

I run this query in the sql management studio and it works fine. but seems like it doesn't work in the stored procedure

Can I not use a LIKE '%' in an integer field?

here is my stored procedure

Expand|Select|Wrap|Line Numbers
  1. USE [ReefJunkies]
  2. GO
  3. /****** Object:  StoredProcedure [dbo].[SearchLibraryFish]    Script Date: 11/06/2010 21:22:50 ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. ALTER PROCEDURE [dbo].[SearchLibraryFish]
  9.  
  10. @CommonName Varchar(max),
  11. @ReefCompatibilityID int,
  12. @ReefCareLevelID int,
  13. @ReefFamilyID int,
  14. @FishTypeID int,
  15. @ReefSpeciesID int,
  16. @ReefDietID int,
  17. @ReefTemperamentID int
  18.  
  19.  
  20. AS
  21.  
  22. SET @CommonName= '%' + @CommonName + '%'
  23. SET @ReefCompatibilityID= @ReefCompatibilityID + '%'
  24. SET @ReefCareLevelID= @ReefCareLevelID + '%'
  25. SET @ReefFamilyID= @ReefFamilyID + '%'
  26. SET @FishTypeID= @FishTypeID + '%'
  27. SET @ReefSpeciesID= @ReefSpeciesID + '%'
  28. SET @ReefDietID= @ReefDietID + '%'
  29. SET @ReefTemperamentID= @ReefTemperamentID + '%'
  30.  
  31. SELECT *
  32. FROM  FishLibrary INNER JOIN
  33.                FishType ON FishLibrary.FishTypeID = FishType.FishTypeID INNER JOIN
  34.                ReefCompatibility ON FishLibrary.ReefCompatibilityID = ReefCompatibility.ReefCompatibilityID INNER JOIN
  35.                ReefCareLevel ON FishLibrary.ReefCareLevelID = ReefCareLevel.ReefCareLevelID INNER JOIN
  36.                ReefFamily ON FishLibrary.ReefFamilyID = ReefFamily.ReefFamilyID INNER JOIN
  37.                ReefSpecies ON FishLibrary.ReefSpeciesID = ReefSpecies.ReefSpeciesID INNER JOIN
  38.                ReefDiet ON FishLibrary.ReefDietID = ReefDiet.ReefDietID INNER JOIN
  39.                ReefTemperament ON FishLibrary.ReefTemperamentID = ReefTemperament.ReefTemperamentID
  40. WHERE (FishLibrary.CommonName LIKE @CommonName) AND (FishLibrary.ReefCompatibilityID LIKE @ReefCompatibilityID) AND 
  41.                (FishLibrary.ReefCareLevelID LIKE @ReefCareLevelID) AND (FishLibrary.ReefFamilyID LIKE @ReefFamilyID) AND (FishLibrary.FishTypeID LIKE @FishTypeID) AND
  42.                 (FishLibrary.ReefSpeciesID LIKE @ReefSpeciesID) AND (FishLibrary.ReefDietID LIKE @ReefDietID) AND 
  43.                (FishLibrary.ReefTemperamentID LIKE @ReefTemperamentID)
  44.  
  45.  
Nov 7 '10 #1
1 3825
gpl
152 100+
Like '%...' is a string comparison -- how is one number like another ?

To make this work, you would have to convert the integers to strings, then make the comparison.
Nov 7 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Saso Zagoranski | last post by:
Hi! I have created an SqlCommand object and I have set some parameters to it... One of the parameters is of the DateTime type; here is the code: sqlCommand.Parameters.Value =...
1
by: Sebastian Mark | last post by:
Did anyone got error like that? When I'm trying to Update WebReference in my project this is an error I'm getting "Custom tool error: Failed to generate dataset. Undefined data type:...
1
by: Carmen Wai | last post by:
Hello: What is the maximum size of varchar(n) for a field in a row in postgresql 7.2.1? Thank a lot! Carmen _________________________________________________________________ Get 10Mb...
4
by: darrel | last post by:
I'm getting this error: Arithmetic overflow error converting numeric to data type numeric. Triggered on this line of my code: objOleDbAdapter.Fill(DS, "rss") Everything works when this is...
1
by: sonata | last post by:
I am trying to compare two fields which are char data typr. BUT the comparision must be arithemetic in nature. so i tried to cast both the data base field and my parameter field to big int...
2
by: Hulikal | last post by:
Hi, I using the following query select dateadd(s, 1185255439727, '01-01-1970 05:30:00') on MSSQL 2005. I get the error Arithmetic overflow error converting expression to data type...
5
by: ITCraze | last post by:
Please Guys help me out , as I need the solution of this problem very fast.Please help me. My table contains a varchar field which contains time like : 04:09PM Now the problem is that I have...
2
by: bipinskulkarni | last post by:
Hi, i have a field createdby with datatype GUID. In following query ,i encountered with the error "Conversion failed when converting from a character string to uniqueidentifier" select...
9
by: gggram2000 | last post by:
I need some help, cant figure out the error. SqlConnection dbConnection = new SqlConnection(xmldb); dbConnection.Open(); string sql = "SELECT InvStatus FROM SaleReceipts Where AccNum = '" +...
5
by: Joell | last post by:
When I try to insert values into an existing table, I am getting the following error. The table is not in bit data type format and neither is the target table. Conversion failed when converting the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.