Click to See Complete Forum and Search --> : [RESOLVED] Wondering why this doesn't work
stin
October 17th, 2007, 04:27 PM
The following code produces 0 results, however, if I replace '%' with '%%' I get the entire table returned. Any ideas?
declare @blah char(2)
set @blah = '%'
SELECT * FROM dwJobs WHERE cono LIKE @blah
hspc
October 18th, 2007, 05:12 AM
because CHAR is a fixed length string, it will padded with spaces.
So when you assign '%' to it it will be equal to '% ' (note the space)
So your query will be :
SELECT * FROM dwJobs WHERE cono LIKE '% '
which will return records with 'cono' Starts with anything and has the last character equal to space.
using VARCHAR instead of CHAR can solve this problem.
stin
October 18th, 2007, 08:39 AM
Thanks a bunch. That's just what the doctor ordered.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.