[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Print the portion of a string past a special character

Posted on 2012-09-06
4
Medium Priority
?
373 Views
Last Modified: 2012-09-06
Hi,

How would I go about editing this script to update my column with only the portion of the string after a special character such as . or -  ?

update TABLEdata		 
set emailGrouping=case when employeestatus!='Terminated' and emailGrouping is null and DepartmentCode like '2%' 
				then substring(DepartmentDescription, 8, 45) 
		 When employeestatus!='Terminated' and emailGrouping is NOT null and DepartmentCode like '2%'
				then emailGrouping+', '+substring(DepartmentDescription, 8, 45) else emailgrouping
		 end

Open in new window



For example, if a string looks like this after the update script is run:

DD-TheValue-The.Location.Name

I would like it to show:

DD-TheValue
0
Comment
Question by:susnewyork
  • 2
  • 2
4 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 38372935
Do you have more sample values, in the sample you have mentioned, you are selecting everything before the second '-' thats confusing
0
 
LVL 1

Author Comment

by:susnewyork
ID: 38372948
That's basically what I need.

Another example of what would need to be excluded would be this:

DD-2ndValue.LocationDate

I would need:

DD-2ndValue from that string.
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 total points
ID: 38373000
try this way

declare @str varchar(100) ='DD-2ndValue.LocationDate'

select left (@Str, (case when CHARINDEX('-',@Str,4) = 0 then CHARINDEX('.',@Str,4)  else CHARINDEX('-',@Str,4) end ) -1 )
0
 
LVL 1

Author Closing Comment

by:susnewyork
ID: 38373585
Perfect, thanks.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

834 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