Solved

how to substring based on the first instance of a character

Posted on 2013-12-31
2
249 Views
Last Modified: 2014-01-01
I want to substring to get position 13 to the position just before the first semi-colon.

The string is
Data Source=edwdev02; User Name=med_query_user; Server=codenamed;

I want to end up with edwdev02

So something like
Select substring(my_variable,13,instring_position(my_variable,';') - 1)
From such_and_such
Where this_and_that
0
Comment
Question by:Alaska Cowboy
2 Comments
 
LVL 23

Accepted Solution

by:
Mysidia earned 250 total points
ID: 39749396
Try

SELECT
   CASE WHEN  charindex(';',my_variable, 13)  > 0  
            THEN substring(my_variable,13,charindex(';',my_variable, 13) - 13)
             ELSE  NULL
   END

From such_and_such
Where this_and_that
Go
0
 
LVL 1

Author Comment

by:Alaska Cowboy
ID: 39749949
Mysidia,

worked ! 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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

863 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

23 Experts available now in Live!

Get 1:1 Help Now