Friday, February 24, 2012

how can I use (contains) in stored procedeure?

how can I use:

where field_name LIKE '%' + variable + '%'

in stored procedure?

I tried field_name = %@.variable% but didn't work..

field_name LIKE '%' + variable + '%' should work, exactly as you have it.

Can you post more of the code that is not working?

|||

Use

where field_name LIKE '%' + @.variable + '%'

instead of

where field_name LIKE '%' + variable + '%'

You need to add the "@." character to your variable name.

Regards,

|||

this is the error I am getting followed by the stored procedure:

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Special Numbers/www.yahoo.com

the Stored Procedure:

set ANSI_NULLS ON

set QUOTED_IDENTIFIER ON

GO

-- =============================================

-- Author: <Author,,Name>

-- Create date: <Create Date,,>

-- Description: <Description,,>

-- =============================================

ALTER PROCEDURE [shopnumbers].[sp_get_latest_number]

-- Add the parameters for the stored procedure here

-- <@.Param1, sysname, @.p1> <Datatype_For_Param1, , int> = <Default_Value_For_Param1, , 0>,

-- <@.Param2, sysname, @.p2> <Datatype_For_Param2, , int> = <Default_Value_For_Param2, , 0>

@.country_code int

AS

BEGIN

-- SET NOCOUNT ON added to prevent extra result sets from

-- interfering with SELECT statements.

SET NOCOUNT ON;

-- Insert statements for procedure here

-- SELECT category.[category_english_name] + ' - ' + category.[sub_category_english_name] AS full_category_name, numbers.the_number, numbers.created_date FROM owners INNER JOIN (category INNER JOIN numbers ON category.category_id = numbers.category_id) ON owners.owner_id = numbers.owner_id;

SELECT numbers.number_id, numbers.number_guid, country.country_flag, numbers.category_id, numbers.the_number, numbers.created_date, numbers.amount, country.country_english_name, category.category_english_name + ' - ' + category.sub_category_english_name AS full_category_name

FROM numbers

INNER JOIN country ON numbers.country_id = country.country_id

INNER JOIN category ON numbers.category_id = category.category_id

WHERE (numbers.number_disabled <> 'Y') AND country.country_code LIKE '%' + @.country_code + '%'

END

|||

OK.. I know where is the problem.. it was a varChar and I changed it to Int which dosn't allow LIKE.

Thank's any way..

Happy holidays..

No comments:

Post a Comment