Solved

Anyway to simplified my query trim function?

Posted on 2011-03-17
2
278 Views
Last Modified: 2012-05-11
I want to use ltrim(rtrim(degree)) instead of just degree in the query.  Is there a way that I don't have to repeat these trim syntax everywhere?  Thanks.
Update dbo.PersonDegree
	SET degree = 
	case 
		when (degree='M.D.', 'MD, CM', 'MD BS', 'MB, BCh', 'MB, BS', 'M.D./PhD.', 'MB, Ch.B.') then 'MD'
		when (degree in('B.Sc.', 'B.S.', 'B.S', 'BS(High Honors)', 'BS/MS', 'B.sc.', 'BSc')) then 'BS'
		when (degree IN('Ph. D.', 'Ph D', 'Ph.D.', 'Ph.D', 'PhD.')) then 'PhD.'
		when (degree IN('M.S.', 'Masters', 'M. Sci.')) then 'MS'
		when degree='DMD' then 'DDM'
		when degree ='Psy.D' then 'DPSY'
		when degree in('B.A', 'B.A.') then 'BA'
		when degree='B.M.S.' then 'BMS'
		when degree='D.O.' then 'DO'
		when degree='DNSC' then 'DSN'
		when degree='M.A.' then 'MA'
		when degree='M.B.B.S' then 'MD'
		when degree='MS.B' then 'MSB'
		when degree='P.A.' then 'PA'
		when degree='MSN BS' then 'MSN'
		when degree='M. Phil.' then 'MS'
		when degree in('MS Ed', 'MS Ed.') then 'MSEd'
		ELSE degree
	End

Open in new window

0
Comment
Question by:lapucca
2 Comments
 
LVL 69

Accepted Solution

by:
Qlemo earned 500 total points
ID: 35158538
You can use a derived table:
Update PD
set degree =
  case 
    when (tdegree='M.D.', 'MD, CM', 'MD BS', 'MB, BCh', 'MB, BS', 'M.D./PhD.', 'MB, Ch.B.') then 'MD'
    when (tdegree in('B.Sc.', 'B.S.', 'B.S', 'BS(High Honors)', 'BS/MS', 'B.sc.', 'BSc')) then 'BS'
    when (tdegree IN('Ph. D.', 'Ph D', 'Ph.D.', 'Ph.D', 'PhD.')) then 'PhD.'
    when (tdegree IN('M.S.', 'Masters', 'M. Sci.')) then 'MS'
    when tdegree='DMD' then 'DDM'
    when tdegree ='Psy.D' then 'DPSY'
    when tdegree in('B.A', 'B.A.') then 'BA'
    when tdegree='B.M.S.' then 'BMS'
    when tdegree='D.O.' then 'DO'
    when tdegree='DNSC' then 'DSN'
    when tdegree='M.A.' then 'MA'
    when tdegree='M.B.B.S' then 'MD'
    when tdegree='MS.B' then 'MSB'
    when tdegree='P.A.' then 'PA'
    when tdegree='MSN BS' then 'MSN'
    when tdegree='M. Phil.' then 'MS'
    when tdegree in('MS Ed', 'MS Ed.') then 'MSEd'
    ELSE tdegree
  End
from (select *, ltrim(rtrim(degree)) as tdegree from dbo.PersonDegree) PD

Open in new window

0
 

Author Closing Comment

by:lapucca
ID: 35158667
Cool!  Thanks.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to set UNMASK permission only to only one table in SQL Server 2016 ? 11 75
SQL Pivot Rows To Columns 10 51
SYbase 4 24
Help Required 3 89
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now