473,739 Members | 7,912 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create/Using Stored Procedures WITH Wildcards

3 New Member
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 3167
ilearneditonline
130 Recognized Expert New Member
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
PilotHaz
3 New Member
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 Recognized Expert New Member
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
PilotHaz
3 New Member
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
2310
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, delete, use, etc.. stored procedures soley from asp (i.e., no GUI or console- like being hosted on Brinkster)? The tutorial on aspfaq.com mentions that stored procedures can be
4
8101
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 creates a string of custom SQL statement and returns this string back to the main stored procedure. This SQL statements work fine on there own. The SQL returned from the sub stored procedure are returned fine. The datatype of the variable that...
10
2163
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 that you can't issue a USE command within a procedure. So my question is either - how do I get around this?
2
2821
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 code in stored procedures (im advocating encryption of them). When deploying an application however stored procedure seem to add another level of complexity to installation. In future we also plan to have an basic ASP app with some of the...
14
3652
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 scenario: 1) create proc using query analyzer and CREATE PROC spHAPPY syntax 2) open this proc in ADP
0
1048
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 upgraded to Visual Studio 2003, but create/edit for tables and stored procedures does not seem to exist through the Server Explorer window. 2003's help instructions on creating a stored procedure is the same as 2002, but the only this on the...
5
6483
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 which other clauses are appended with AND. This all works fine as long as I provide a condition for the first clause
1
1902
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 step..
5
36644
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 LIKE @ProductName" in WHERE clause of a select statement, and a stored procedure uses the user defined function while passing @ProductName input parameter to the user defined function, is there any security risks? Is there a better way to construct...
0
8969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9209
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8215
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6754
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6054
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4826
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.