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
 General SQL Server Forums
 New to SQL Server Programming
 Can % in variable value act as wildcard?

Author  Topic 

phrankbooth
Posting Yak Master

162 Posts

Posted - 2009-12-02 : 11:12:37
Hi,

I get a field value with a query and the value is this: @myvar = '%.ABC'

Can I then say this: Select Y from table where X Like @myvar

Expecting the % in @myvar to act as wildcard?

If not, how can I do this?

Thanks!

--PhB

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2009-12-02 : 12:05:55
You mean like this?


declare @table table (x varchar(9), y int)
insert @table
select 'XYZ.ABC', 1
union all select '.ABC', 2
union all select 'ABC.ABD', 3

declare @myvar varchar(9)
set @myvar = '%.ABC'

Select Y from @table where X Like @myvar


Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-12-02 : 12:56:16
"Process Improvement Manager"

I LIKE IT

http://www.sqlteam.com/forums/pop_profile.asp?mode=display&id=21743



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2009-12-02 : 13:06:55
quote:
Originally posted by X002548

"Process Improvement Manager"

I LIKE IT

http://www.sqlteam.com/forums/pop_profile.asp?mode=display&id=21743


Thanks

Maybe "Yak of all trades" would be better?.


Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page

phrankbooth
Posting Yak Master

162 Posts

Posted - 2009-12-02 : 14:11:51
Yes that's it! Thanks!

--PhB
Go to Top of Page
   

- Advertisement -