Solved

how to substring based on the first instance of a character

Posted on 2013-12-31
2
252 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

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…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
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…
Viewers will learn how the fundamental information of how to create a table.

803 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