Question : pass parameter value with wild card

I am trying to create a SP passing 3 parameters (CUSTNMBR, COMMNTID, and  BACHNUMB) with and without wild cards. I have tried it with CUSTNMBR to see if I could get it to work, no errors but no results either I also tried it as a select statement with the same results, nothing. Any help would be appreciated.  BTW the COMMNTID is a text field
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
Query Statement

declare @CUSTNMB char(21)
set @CUSTNMB = 'L4'


SELECT     SOP30200.CUSTNMBR, SOP30200.COMMNTID, SOP30200.SOPNUMBE, SOP30200.ORIGNUMB, SOP30200.DOCDATE, SOP30200.BACHNUMB, 
                      SOP30200.CUSTNAME, SOP30300.ITEMNMBR, SOP30300.ITEMDESC, SOP30300.QUANTITY, SOP30300.UNITCOST, SOP30300.EXTDCOST
FROM         SOP30200 INNER JOIN
                      SOP30300 ON SOP30200.SOPTYPE = SOP30300.SOPTYPE AND SOP30200.SOPNUMBE = SOP30300.SOPNUMBE
WHERE     (SOP30200.CUSTNMBR LIKE '%'+ @CUSTNMB+'%'  ) AND (SOP30200.COMMNTID = 'PURG 8/23/2010')
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
StordProc

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[POrders]
@CUSTNMB char(21)
as
BEGIN
SELECT     SOP30200.CUSTNMBR, SOP30200.COMMNTID, SOP30200.SOPNUMBE, SOP30200.ORIGNUMB, SOP30200.DOCDATE, SOP30200.BACHNUMB, 
                      SOP30200.CUSTNAME, SOP30300.ITEMNMBR, SOP30300.ITEMDESC, SOP30300.QUANTITY, SOP30300.UNITCOST, SOP30300.EXTDCOST
FROM         SOP30200 INNER JOIN
                      SOP30300 ON SOP30200.SOPTYPE = SOP30300.SOPTYPE AND SOP30200.SOPNUMBE = SOP30300.SOPNUMBE
WHERE     (SOP30200.CUSTNMBR LIKE '%'+ @CUSTNMB+'%'  ) AND (SOP30200.COMMNTID = 'PURG 8/23/2010')AND (SOP30200.BACHNUMB = 'DGH');
END;

Answer : pass parameter value with wild card

Declare your variable as varchar(21) instead of char(21); using char(21) is causing a lot of spaces :)

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
declare @CUSTNMB char(21), @CUSTNMB2 varchar(21)
set @CUSTNMB = 'L4'
set @CUSTNMB2 = 'L4'
 
select '%' + @CUSTNMB + '%' AS WithChar, '%' + @CUSTNMB2 + '%' AS WithVarChar
 
/* returns:
 
WithChar                 |  WithVarChar
-------------------------|-------------
%L4                   %  |  %L4%
 
*/
Random Solutions  
 
programming4us programming4us