473,379 Members | 1,278 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,379 software developers and data experts.

Create/Using Stored Procedures WITH Wildcards

I have currently looked through a couple of the posts on here about Stored Procedures but using this information did not work. Here is what I have done. I am trying to use wild cards for I want to search through my database for specific Programs that have been added to the database from the computer's login script.

In my search I want to call a stored procedure to make it easier then making a call each time (and just to use the one that is already created.)

Here is the sp code:
Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE [dbo].[sp_SrchProgramsByProgramName]
  2. @program char(100) 
  3. AS
  4. SELECT * FROM Programs
  5. WHERE ProgramName LIKE '%' + @program + '%'
  6. GO
  7.  
This is the call I was trying to use in SQL Query Analyzer for it:
Expand|Select|Wrap|Line Numbers
  1. execute dbo.sp_SrchProgramsByProgramName 'Adobe'
  2.  
Yet, it is returning nothing for the results. If I do the exact names I know the results will show up but I want to have it so if we are looking up just Adobe Products or just AutoCAD, if there is other things in the programName string then it won't matter.

Please if you would be able to help me it would be greatly appreciated.
Aug 1 '07 #1
4 3144
ilearneditonline
130 Expert 100+
You don't have to worry with concat on the where clause.

Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE [dbo].[sp_SrchProgramsByProgramName]
  2. (
  3.     @program char(100)
  4. )
  5.     AS
  6.     SELECT * FROM Programs
  7.     WHERE ProgramName LIKE '%@program%'
Aug 1 '07 #2
You don't have to worry with concat on the where clause.

Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE [dbo].[sp_SrchProgramsByProgramName]
  2. (
  3.     @program char(100)
  4. )
  5.     AS
  6.     SELECT * FROM Programs
  7.     WHERE ProgramName LIKE '%@program%'
That doesn't work. I had tried that before as well, it comes back with 0 rows affected.
Aug 2 '07 #3
ilearneditonline
130 Expert 100+
That doesn't work. I had tried that before as well, it comes back with 0 rows affected.
This does work, I have it working here. Don't use a char for your parameter, that has additional whitespace and I have not been able to get it to work. Declare a varchar variable to hold the criteria with the `%` already added.

Expand|Select|Wrap|Line Numbers
  1.  CREATE PROCEDURE [dbo].[sp_SrchProgramsByProgramName] 
  2. (
  3. @program varchar(100)
  4. )
  5. AS
  6. DECLARE @criteria varchar(102)
  7. SET @criteria = '%' + @program + '%' 
  8. SELECT * FROM Programs
  9. WHERE ProgramName LIKE @criteria
  10.  
Aug 2 '07 #4
This does work, I have it working here. Don't use a char for your parameter, that has additional whitespace and I have not been able to get it to work. Declare a varchar variable to hold the criteria with the `%` already added.

Expand|Select|Wrap|Line Numbers
  1.  CREATE PROCEDURE [dbo].[sp_SrchProgramsByProgramName] 
  2. (
  3. @program varchar(100)
  4. )
  5. AS
  6. DECLARE @criteria varchar(102)
  7. SET @criteria = '%' + @program + '%' 
  8. SELECT * FROM Programs
  9. WHERE ProgramName LIKE @criteria
  10.  
Thank you very much. I see that it was the actual char I believe like you said. Varchar works fine with it. Thanks again.
Aug 2 '07 #5

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

Similar topics

10
by: Dragonhunter | last post by:
Hello, The aspfaq.com seems to really push stored procedures, and I hear the same advice here all the time. So I want to take the advice. Is it possible to create and practically maintain,...
4
by: MD | last post by:
I am trying to create a dynamic SQL statement to create a view. I have a stored procedure, which based on the parameters passed calls different stored procedures. Each of this sub stored procedure...
10
by: John A Fotheringham | last post by:
I'm trying to write a procedure that having created a new database, will then create within that new database all the tables and procedures that go with it. In doing this I'm hitting the problem...
2
by: scott | last post by:
Hi, Just wondering what sort of problems and advantages people have found using stored procedures. I have an app developed in VB6 & VB.NET and our developers are starting to re-write some of the...
14
by: aaron kempf | last post by:
I find that ADP does not support any Stored Procedures that use the 'CREATE PROC spHAPPY' syntax. CREATE PROC syntax is listed in books online. This syntax should be supported Here is a...
0
by: William F. Robertson, Jr. | last post by:
I know this is a little off topic, but I can't seem to figure this out. In Visual Studio 2002 I was creating and edit stored procedures and tables using the server explorer tab. We recently...
5
by: Dave | last post by:
I need to filter an Access 2000 result set in ASP 30 using the ADO recordset.filter. I build the filter in pieces. The first clause of the filter is this... WHERE word LIKE 'S%' ... to...
1
by: mmikram | last post by:
Hi, I am new to DB2, My installation of DB does not include Development center... but i need to create stored procedures. Geeks please help me how to create stored procedure and please step by...
5
by: nidaar | last post by:
From a security point of view, is accepting wildcards like "%" in input parameters of stored procedures against any best practices? As an example, if a user defined function uses "Productname...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.