Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

LIKE statement with Parameter Problem Expand / Collapse
Author
Message
Posted Friday, February 15, 2013 1:19 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, February 18, 2013 8:17 AM
Points: 5, Visits: 10
Hi, I am trying to add a LIKE statement to a query in report builder 3.0 with a parameter like the one below. It allows the user to input an ID and returns records that have that id in their list of IDs by using the like statement with wildcards.

SELECT
CORRIDOR.OBJECTID
,CORRIDOR.STATUS
,CORRIDOR.DIMENSION
,CORRIDOR.WIDTH
,CORRIDOR.ID
FROM
CORRIDOR
WHERE ID LIKE '%' + @ID + '%'

I get an error "Conversion Failed when Converting the varchar value '%' to data type int"

I am not sure why the wildcard is converting to int. my @ID parameter is text. Please help. Thanks!
Post #1420733
Posted Monday, February 18, 2013 3:51 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, May 01, 2013 4:11 AM
Points: 127, Visits: 507
what is the datatype of the column 'ID' in the database table ?

BI Developer
SSRS, SSIS, SSAS, IBM Cognos, IBM Infosphere Cubing services, Crystal reports, IBM DB2, SQL Server, T-SQL
Please visit... ApplyBI
Post #1421130
Posted Monday, February 18, 2013 6:52 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, February 18, 2013 8:17 AM
Points: 5, Visits: 10
nvarchar(250)
Post #1421191
Posted Monday, February 18, 2013 10:40 PM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Today @ 6:24 PM
Points: 408, Visits: 687
This is the exact error you would get if the parameter's datatype is Integer. Double check that.

Another thing you can try is using

like '%' + Cast(@ID as nvarchar(20)) + '%'

instead of

like '%' + @ID  + '%'

Post #1421434
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse