Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Select with Like not working with parameter
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01537428
Message ID:
01537490
Vues:
45
Hi Naomi...just when I thought I was out of the woods !!!
Really weird happenings with Like and % and Parameters
For instance:
'%31025c1%'   Selects
   '%025c1%    Selects
   '%25c1%'    and  '%5c1%'   and '%c1%   will not select any rows  (e.g. below I jave these in :Invref)
(I cant understand if the top two above select ok, why the last 3 will not  (Parameters and SqlServer Field all Char(10)

The LIke and % seems to not work on the Last Few charactes of a string.....always seems to be ok if I do a select based on the starting characters.......I thought the thing about % was that it was a kind of wild card thing 


My Full StoredProc is:


USE [KFS]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[spFindItr] 
	-- Add the parameters for the stored procedure here
	@OrderFrom Date ,   @OrderTo Date,
	@Cusref Char(10),	@Ordref Char(10),	@Desref Char(10),	@Invref Char(10), @Cusname VarChar(30)
	
	
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 
	ITR_PK,ITR_STAGE,ITR_CUSREF,ITR_ORDREF,ITR_CUSORD,ITR_DESREF,ITR_INVREF,ITR_ORDDAT,ITR_DESDAT,ITR_INVDAT,
	ITR_LOC,ITR_CURR,ITR_GRSVAL,ITR_DISVAL,ITR_NETVAL,ITR_VATVAL,ITR_TOTVAL,ITR_ALLVAL,ITR_BALOS,
	SMA_NAME 
	From Itr
	Join Sma on ITR_CUSREF = SMA_CUSREF
	Where 
	  ITR_ORDDAT lt= @OrderFrom and ITR_ORDDAT gt= @OrderTo and
	  (@Cusref  = '%%' or ITR_CUSREF Like @Cusref )    and
	  (@Ordref  = '%%' or ITR_ORDREF Like @Ordref )    and 
	  (@Desref  = '%%' or ITR_DESREF Like @Desref )    and 
	  (@Invref  = '%%' or ITR_INVREF Like @Invref )    and
	  (@Cusname = '%%' or SMA_NAME   Like @Cusname )    
	    
	  
	  END

Regards,
Gerard
--------------------------------------------------------------------------------------------------------------------
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform