all groups > sql server programming > march 2005 >
You're in the

sql server programming

group:

Strange problem with stored procedure parameter


Re: Strange problem with stored procedure parameter Louis Davidson
3/1/2005 4:41:15 PM
sql server programming:
The problem is that the char value gets padded so what you are actually
looking for is:

'% '

Rather than

'%'

So any number of characters followed by 20 spaces is not what you want
probably. It is confusing, to be sure. For example take this code:

declare @char char(60)
set @char = '%'
select '*' + @char + '*'

This returns:

--------------------------------------------------------------
*% *

Use varchar and you won't have this problem.


--
----------------------------------------------------------------------------
Louis Davidson - drsql@hotmail.com
SQL Server MVP

Compass Technology Management - www.compass.net
Pro SQL Server 2000 Database Design -
http://www.apress.com/book/bookDisplay.html?bID=266
Blog - http://spaces.msn.com/members/drsql/
Note: Please reply to the newsgroups only unless you are interested in
consulting services. All other replies may be ignored :)
[quoted text, click to view]

Re: Strange problem with stored procedure parameter Michael C#
3/1/2005 5:13:27 PM

[quoted text, click to view]

CREATE PROCEDURE get_books_by_title @title varchar(60)
AS
SELECT * FROM Books
WHERE Title LIKE @title
GO

Strange problem with stored procedure parameter gemel
3/1/2005 10:10:06 PM
I have a simple stored procedure that is defined as shown below:

CREATE PROCEDURE get_books_by_title
@title char(60)
AS
SELECT * FROM Books
WHERE Title LIKE @title
GO

I call this procedure witha wildcard as shown:

exec dbo.get_books_by_title '%'

but this only returns 4 out of the 12 entries on the table. The
strange thing is, when I reduce the size of the parameter to 20
characters then I get all entries returned. As I start to increase the
number of characters defined for the parameter I get more and more
lines not being returned from the table.

Any help would be gratefully appreciated.

Regards

AddThis Social Bookmark Button