Solved

how to substring based on the first instance of a character

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

820 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