Home All Groups Group Topic Archive Search About
Author
24 Mar 2006 11:54 AM
Enric
Dear all,
I can't work out with this query:
declare @var char(20)
set @var = 'look%'
select name from table where field like @var
No return rows when there is a lot
Any input or advice would be very appreciated.
--
Current location: Alicante (ES)

Author
24 Mar 2006 11:58 AM
Enric
my goodness i was using char type when the field waits for varchar.
--
Current location: Alicante (ES)


Show quote
"Enric" wrote:

> Dear all,
> I can't work out with this query:
> declare @var char(20)
> set @var = 'look%'
> select name from table where field like @var
> No return rows when there is a lot
> Any input or advice would be very appreciated.
> --
> Current location: Alicante (ES)
Author
24 Mar 2006 11:59 AM
Tibor Karaszi
make it varchar(20)  instead of char(20)

Show quote
"Enric" <vta***@terra.es.(donotspam)> wrote in message
news:4A0A2628-779B-4C51-B324-F9E6ADC59555@microsoft.com...
> Dear all,
> I can't work out with this query:
> declare @var char(20)
> set @var = 'look%'
> select name from table where field like @var
> No return rows when there is a lot
> Any input or advice would be very appreciated.
> --
> Current location: Alicante (ES)
Author
24 Mar 2006 1:07 PM
Wayne Snyder
The reason you should use Varchar instead of char is that char fields pad
with spaces at the end... So when you though you were searching for field
like 'look%' you  were really asking for field like 'look%          '
and of course, none were found.
--
Wayne Snyder MCDBA, SQL Server MVP
Mariner, Charlotte, NC

I support the Professional Association for SQL Server ( PASS) and it''s
community of SQL Professionals.


Show quote
"Enric" wrote:

> Dear all,
> I can't work out with this query:
> declare @var char(20)
> set @var = 'look%'
> select name from table where field like @var
> No return rows when there is a lot
> Any input or advice would be very appreciated.
> --
> Current location: Alicante (ES)
Author
24 Mar 2006 1:16 PM
Enric
Thanks to both,
so that now the question is, if you have to choose between char(1) and
varchar(1) what most expensive is? which will requires more space?
--
Current location: Alicante (ES)


Show quote
"Wayne Snyder" wrote:

> The reason you should use Varchar instead of char is that char fields pad
> with spaces at the end... So when you though you were searching for field
> like 'look%' you  were really asking for field like 'look%          '
>  and of course, none were found.
> --
> Wayne Snyder MCDBA, SQL Server MVP
> Mariner, Charlotte, NC
>
> I support the Professional Association for SQL Server ( PASS) and it''s
> community of SQL Professionals.
>
>
> "Enric" wrote:
>
> > Dear all,
> > I can't work out with this query:
> > declare @var char(20)
> > set @var = 'look%'
> > select name from table where field like @var
> > No return rows when there is a lot
> > Any input or advice would be very appreciated.
> > --
> > Current location: Alicante (ES)
Author
24 Mar 2006 3:01 PM
Tibor Karaszi
Varchar has an overhead of 2 bytes.

Show quote
"Enric" <vta***@terra.es.(donotspam)> wrote in message
news:14570AE8-82C7-4205-9B54-16B0E395CA4D@microsoft.com...
> Thanks to both,
> so that now the question is, if you have to choose between char(1) and
> varchar(1) what most expensive is? which will requires more space?
> --
> Current location: Alicante (ES)
>
>
> "Wayne Snyder" wrote:
>
>> The reason you should use Varchar instead of char is that char fields pad
>> with spaces at the end... So when you though you were searching for field
>> like 'look%' you  were really asking for field like 'look%          '
>>  and of course, none were found.
>> --
>> Wayne Snyder MCDBA, SQL Server MVP
>> Mariner, Charlotte, NC
>>
>> I support the Professional Association for SQL Server ( PASS) and it''s
>> community of SQL Professionals.
>>
>>
>> "Enric" wrote:
>>
>> > Dear all,
>> > I can't work out with this query:
>> > declare @var char(20)
>> > set @var = 'look%'
>> > select name from table where field like @var
>> > No return rows when there is a lot
>> > Any input or advice would be very appreciated.
>> > --
>> > Current location: Alicante (ES)

AddThis Social Bookmark Button