Monday, February 3, 2014

SQL, Excel, MS Access: First Word in String

Some examples, find out yourself, hope this helps

IN SQL

--Taking the first word of the Partner Name (FIELD) in this case
(CASE WHEN CHARINDEX(' ',[FIELD]) = 0 THEN UPPER([FIELD])
 ELSE REPLACE(UPPER(SUBSTRING(LTRIM([FIELD]),1,CHARINDEX(' ',[FIELD]))),',','')
 END)



IN EXCEL
=IF(ISERROR(LEFT(B2,FIND(" ",B2)-1)),B2,LEFT(B2,FIND(" ",B2)-1))


IN ACCESS
TRIM(Left([Yourfieldname], InStr([Yourfieldname], " ")))



Read More

No comments:

Post a Comment