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

LIKE Condition while using parameters

Hi All,

I'm trying to create a search stored procedure within MSSQL.

I've come up with the following:
Expand|Select|Wrap|Line Numbers
  1. ALTER PROCEDURE [dbo].[usp_Search]
  2. @SearchText nchar(15)
  3. AS
  4. BEGIN
  5. SELECT *
  6. FROM         dbo.Person
  7. WHERE FirstName LIKE '%'+@SearchText+'%'
  8. END
I've tested this a few times on the test data I have in the database but it does not seem to be working correctly, although when I manually put something in, ie - take the parameter out and type in for example: WHERE FirstName LIKE '%at%' it will work...

Can anyone explain to me what I am doing incorrectly?
Mar 6 '09 #1
4 2323
I just realised this is in the MySQL threads...oops.

It's MS SQL.
Mar 6 '09 #2
Hey Matt,

Try changing @SearchText to nvarchar(15) instead of nchar(15). Since it is char, it is padding the value with spaces so that it is 15 characters in total length. Therefore, when you are searching for 'at' you are really searching for '%at_____________%' (where _ is a space).

Zach
Mar 6 '09 #3
Hi Zach,

I think your onto something there - sounds right.

I'll give it a shot tomorrow and tell you how I go.

Thanks heaps - it's amazing how much I have just learnt if that's all it was.

Cheers,
Matt.
Mar 8 '09 #4
Zach,
Helped heaps - working great now.

Thanks so much,

Matt.
Mar 9 '09 #5

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

Similar topics

6
by: pragile | last post by:
I have a stored procedure that has some problems with slow performance. The procedure has 2 parameters @firstname varchar(100) @lastname varchar(100) These parameters can have values like a%,...
9
by: Mike P | last post by:
I know everything about reference counting and making sure you don't have large objects lying around. I have also profiled my app with multiple tools. I know about the fact GC collects memory but...
0
by: xixi | last post by:
hi, we are using db2 udb v8.1 on win 64 bit with fp3 with type 4 db2jcc.jar driver. when i execute this query , select id, arno01, arcd01, arno16, artx01, armo09, ardy09, arcc09, aryr09,...
3
by: Sunil Korah | last post by:
I dont know whether this is a stupid question. But does access have something akin to the pointer variable in C - or for that matter the '&' operator in xbase. I will explain my reason for...
2
by: mr_mach7 | last post by:
I have a situation in which I want to dynamically build a SQL statement based upon criteria. The statement would contain different fields depending upon the criteria. I created a Stored Procedure...
24
by: Agnes | last post by:
my date format is in yyyy-mm-dd mycommandtext is 'select * from myTable where issuedate >='" & Me.txtStartDate.text & "' and issuedate <= '" & Me.txtEndDate.text & "' " It return zero records,...
11
by: Dan Sugalski | last post by:
Is there any good way to speed up SQL that uses like and has placeholders? Here's the scoop. I've got a system that uses a lot of pre-generated SQL with placeholders in it. At runtime these SQL...
3
by: Yohan | last post by:
Hello, I have a question concerning the template classes and their parameters. Is it possible to set a condition on the template parameters in a way that could block the compilation if the...
8
by: =?Utf-8?B?UmljaA==?= | last post by:
Is it possible to find the end of an If block in VB2005 -- similar to C# where in C# if you place your cursor next to a bracket and press ctrl something it highlights the ending bracket? I have...
0
by: tg | last post by:
I have been using the online reorg for over 2 years without any problems. I have just encountered a log full condition after having started the online reorg on the same table that I have been...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
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...

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.