473,804 Members | 3,373 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Wildcards in SQL Server stored procedures

I thought this problem would go away over the Christmas holiday, but
of course it did not. I'm trying to write a stored procedure
incorporating wildcards, so I can search for variations. Example, if
name 'Smith' is submitted, sproc should retrieve all records
containing 'John Smith', 'Zenia Smith', 'Smithfield & Co.' You get the
idea.

Using SQL Query Analyzer, the query

select * from file
where name like '%smith%'

works like a charm.

But if I write a stored procedure declaring the variable @name and
using a where clause 'where name like '%@name%'', I get zero results.
The query doesn't bomb. It just doesn't produce anything - even though
I know there are records that meet the criteria.

Any ideas? Or are sprocs and wildcards incompatible?
Jul 20 '05 #1
1 10634
Ralph Noble (ra*********@ho tmail.com) writes:
But if I write a stored procedure declaring the variable @name and
using a where clause 'where name like '%@name%'', I get zero results.
The query doesn't bomb. It just doesn't produce anything - even though
I know there are records that meet the criteria.


Insert someone called John @nameson (yes, with at-sign and all) and you will
get a result.

Unlike languages like Perl or Unix Shells there is interpolation of
variables in T-SQL, so you need to write:

LIKE '%' + @name + '%'
--
Erland Sommarskog, SQL Server MVP, so****@algonet. se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
16883
by: polytimi8 | last post by:
Hello, I would like to know if it is possible to create a form in Access2000, which would function like a calendar for 8 operating rooms in hospital, showing which hours are those closed for a specific date. For this intersection I would like to be appeared the name of the doctor, the name of the patient and the kind of operation. Furthemore I would like this intersection to be marked in the calendar with a colour, showing that this...
2
7325
by: Yves Touze | last post by:
Hi All, I'm trying to migrate from SQL Server 7.0 to SQL Server 2000. I've got some ASP page which call VB components that retrieve shaped recordsets from SQL Server using the MSDATASHAPE provider. Precisely, here is the code i have Dim Cmdobj As New ADODB.Command Cmdobj.ActiveConnection = oconn Cmdobj.CommandType = adCmdStoredProc
5
3500
by: gilles27 | last post by:
I've ready many of the posts on this and other newsgroups in which people describe working practices for source control of database scripts. We are looking to implement something similar in my current workplace. We have agreed that developers should not modify objects such as views or stored procedures directly, they should check the script out of VSS first, modify it, run it, and then check it back in. The problem we are having is...
11
10760
by: jrefactors | last post by:
I want to know the differences between SQL Server 2000 stored procedures and oracle stored procedures? Do they have different syntax? The concept should be the same that the stored procedures execute in the database server with better performance? Please advise good references for Oracle stored procedures also. thanks!!
15
7263
by: brettclare | last post by:
I have linked a large SQL Server table to Access, however 'only' 2,195,439 records are shown and are available to query. Can I increase the size (cache??)/number of records showing in Access? Thank you.
0
2657
by: Amber | last post by:
Stored procedures are faster and more efficient than in-line SQL statements. In this article we will look at two SQL Server stored procedures; one using an input parameter and one not, and see how to call them from an ASP.Net page Every modern database system has a stored procedure language. SQL Server is no different and has a relatively sophisticated and easy to use system. This article will not attempt to go into depth in explaining...
1
1789
by: nde_plume | last post by:
I have a SQL Server database that is connected to a client server program via ADO. I want this same program to be able to use JET as the database back end (to provide a light alternative that doesn't require a full install of MSDE or SQL Server.) I know that I can't necessarily get a fully automated conversion, but I was wondering what advice group members would have to make this conversion as painless as possible (not to mention keeping...
4
3171
by: PilotHaz | last post by:
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...
5
36652
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
9705
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
9576
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
10567
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6847
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
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4291
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2983
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.