0

afternoon everyone,

I am new to using MSSQL and need help with SUBSTRING function.

i have a strings like below

s2-Total Solids - Std Method
V1E-RVT4/2.5@20degC Initial
V1Y-LVT2/60@20deg Initial
A2-Alkalinity - ISO Method(%)

I would like to only get the data before the first "-" IE

s2
V1E
V1Y
A2

so that i can link two tables in a sql view, would anyone know how i would complete this

can it be done like so?

RTRIM(LEFT (QCTEST.TESTNAME, 10))

3
Contributors
8
Replies
9
Views
6 Years
Discussion Span
Last Post by Mike Bishop
0

thats, i get invalid lenght parameter passed to the substring function

here is my code

SUBSTRING(TestNoName, 1, CHARINDEX('-', TestNoName) - 1)

thanks for your help

0
Select SUBSTRING(TESTNAME,0,CHARINDEX('-',TESTNAME))
--Parameters Of SUBSTRING:   Expression,from,until
--From is passed as 0, because you need first part of the string.
--CHARINDEX is used to get the Index of '-' in TESTNAME
0

See the comments putted on the attached image.

You need to write the query like this:

SELECT SUBSTRING(TestNoName,0,CHARINDEX('-',TestNoName))
Attachments Substring.jpg 85.64 KB
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.