Link to home
Start Free TrialLog in
Avatar of Sam OZ
Sam OZFlag for Australia

asked on

Sql Server query to get substring

Hi  I have  a table  TB-Docs in Sql Server 2016  with a filed Name ( and other fields)  . There are some names ending  like Doc1VOL01 , Doc1VOL11  , Doc1Vol123

Eg.
    Doc1Vol01
    Doc1Vol11    
    Doc3Vol123
 
   I need result with Volume rows and the substring of the  Document name  ( All I need to know is how to get the substring like Doc1 from a string of Doc1Vol01)
        Name                 Doc
        -----                     ----
     Doc1Vol01           Doc1
    Doc1Vol11            Doc1
    Doc3Vol123          Doc3


Edit : Name can be of any length , for example, there can be a Doooooc1Vol01
Avatar of Sam Jacobs
Sam Jacobs
Flag of United States of America image

SELECT LEFT([Name],3) AS Doc

Open in new window

Avatar of Sam OZ

ASKER

Sorry, The document can be of any length , For example there can be DoooooocVol123
So, what is the criteria for the extract? Everything up until Vol?
So, in the example above, you would want Doooooc?
Avatar of Sam OZ

ASKER

That is right- extract  Everything up until Vol
ASKER CERTIFIED SOLUTION
Avatar of Sam Jacobs
Sam Jacobs
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Of course you need to use [TB-Docs] in above query ;-)
Oops ...yes, of course!