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 2005 Forums
 Transact-SQL (2005)
 Simple query help

Author  Topic 

qman
Constraint Violating Yak Guru

442 Posts

Posted - 2008-02-26 : 08:43:15
How do I retrieve all rows from a middle_name column that have a character length of <= 2. This table is populated with middle names and middle initials. I want to isolate the middle initials only.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-26 : 08:48:43
Can you post some sample data with expected result?

Madhivanan

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

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-02-26 : 08:49:40
[code]declare @t table
(
a varchar(10)
)

insert into @t
select 'xxx' union all
select 'yy' union all
select 'z' union all
select 'xyzz' union all
select 'zx' union all
select ''

select * from @t
where a like '__' or a like '_' or a like ''[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

qman
Constraint Violating Yak Guru

442 Posts

Posted - 2008-02-26 : 08:52:09
Some sample data in the middle_name column would be:

A.
B
CCC
DDD DDD

I want to retrieve only the 1 character fields and ultimately assign a '.' to them so that all single characters are formatted as 'X.'
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-26 : 08:56:15
Select columns from table
where col like '[a-zA-Z][.]%'

Madhivanan

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

qman
Constraint Violating Yak Guru

442 Posts

Posted - 2008-02-26 : 09:01:33
Thanks Madhivanan, but that returns all rows with an alpha characters and periods, such as T.E., C., and R.
I want to revive only the rows where the middle_name contains 1 character such as A, B, C

Thanks
Go to Top of Page
   

- Advertisement -