Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Issue with a substring statement 1

Status
Not open for further replies.
Dec 31, 2004
71
GB
Hi All,
I have a table that looks like the below:-

Dell Inc Optiplex 740
Dell Inc. Optiplex 740
Dell Inc. Optiplex 740 eNHANCED

I want to split it into two as per the below :-
Col1 Col2
Dell Optiplex 740
Dell Optiplex 740
Dell Optiplex 740 eNHANCED

I have run the below:-
SELECT LEFT(MAKEANDMODEL, 4) AS Make,substring(MAKEANDMODEL, charindex('DELL', MAKEANDMODEL) + 9, charindex('DELL', MAKEANDMODEL) - (charindex('DELL', MAKEANDMODEL) - 100)) as model
FROM dbo.Table_1

It sort of works but i end up with the below:-
Col1 Col2
Dell Optiplex 740
Dell Optiplex 740
Dell Optiplex 740 eNHANCED

Is there a way to ensure that there is not a space before the values in col2?

Thanks

Nathan
 
Maybe you could use LTrim.

Ex:

Code:
SELECT  LEFT(MAKEANDMODEL, 4) AS Make,
        [!]LTrim([/!]substring(MAKEANDMODEL, charindex('DELL', MAKEANDMODEL) + 9, charindex('DELL', MAKEANDMODEL) - (charindex('DELL', MAKEANDMODEL) - 100))[!])[/!] as model
FROM         dbo.Table_1

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top