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)
 Help to retrieve the above data

Author  Topic 

tsaliki
Starting Member

19 Posts

Posted - 2013-04-15 : 01:14:48
I have a table

create table accounts
(
accname varchar(100),
recstatus bit
)


and records are as follows:

Insert into accounts values ('Pepsi Co',0)
Insert into accounts values ('Pepsi Co',0)
Insert into accounts values ('Prudential',1)
Insert into accounts values ('Lennox International',1)
Insert into accounts values ('Eurosystems (Harveynash Inc) [OLD]',0)
Insert into accounts values ('ETJ Holdings, inc. [OLD]',0)
Insert into accounts values ('I-nnovate [OLD]',1)
Insert into accounts values ('Iflowsoft, LLC [OLD]',1)
Insert into accounts values ('1st OBJECT Inc [OLD]',0)
Insert into accounts values ('Jet Aviation Holdings, Inc [OLD]',0)



Now i want to get the values of the table whose accname contains [old].So please help me

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-15 : 01:19:06
SELECT *
FROM accounts
WHERE accname LIKE '%[[OLD]]'

--
Chandu
Go to Top of Page

stepson
Aged Yak Warrior

545 Posts

Posted - 2013-04-15 : 01:22:26
[code]
select *
from accounts
where accname like '%[[OLD]]%'
[/code]

Ce-am pe mine am si-n dulap, cand ma-mbrac zici ca ma mut
sabinWeb
Go to Top of Page

tsaliki
Starting Member

19 Posts

Posted - 2013-04-15 : 01:25:13
@Thank you bandi
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-15 : 01:27:40
quote:
Originally posted by tsaliki

@Thank you bandi


Welcome

If you want accname ending with [OLD] --> '%[[OLD]]'
If you want accname contains [OLD] --> '%[[OLD]]%'

--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-04-15 : 02:30:30
quote:
Originally posted by stepson


select *
from accounts
where accname like '%[[OLD]]%'


Ce-am pe mine am si-n dulap, cand ma-mbrac zici ca ma mut
sabinWeb



see

http://visakhm.blogspot.in/2013/01/wildcard-character-based-pattern-search.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -