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] "gemel" <jonel@glenavon1.demon.co.uk> wrote in message
news:gop921ta030933al77ui4dcd11jqoqggvq@4ax.com...
>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
>
> John L