Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Variable with wildcards

Author  Topic 

lanamor
Starting Member

8 Posts

Posted - 2011-01-12 : 09:17:13
[code]Set @APP = 'Adobe Flash Player%Plugin'

Select vPackage.Name, vPackage.Version
From vPackage
Where vPackage.Name LIKE @APP

Returns:
Adobe Flash Player 10 ActiveX 10.0.12.36
Adobe Flash Player 10 ActiveX 10.0.2.54
Adobe Flash Player 10 Plugin 10.0.2.54
Adobe Flash Player 10 ActiveX 10.0.32.18
Adobe Flash Player 10 Plugin 10.0.32.18 [/code]

While...
[code]
Select vPackage.Name, vPackage.Version
From vPackage
Where vPackage.Name LIKE 'Adobe Flash Player%Plugin'

Returns:
Adobe Flash Player 10 Plugin 10.0.2.54
Adobe Flash Player 10 Plugin 10.0.32.18 [/code]

Why does the query seem to ignore anything after the first wildcard when using a LIKE and a variable?

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-01-12 : 09:46:13
What do you get?


declare @APP varchar(100)
Set @APP = 'Adobe Flash Player%Plugin'

Select Name
From
(
select 'Adobe Flash Player 10 ActiveX' as name union all
select 'Adobe Flash Player 10 ActiveX' union all
select 'Adobe Flash Player 10 Plugin' union all
select 'Adobe Flash Player 10 ActiveX' union all
select 'Adobe Flash Player 10 Plugin'
) as t
Where Name LIKE @APP


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2011-01-13 : 17:50:21
declare @APP varchar(19) -- ???

=======================================
Elitism is the slur directed at merit by mediocrity. -Sydney J. Harris, journalist (1917-1986)
Go to Top of Page
   

- Advertisement -