For ACE/Jet, I would use the MID()
expression. While the LEFT()
expression would work fine, MID()
is preferable IMO because it makes code more portable i.e. it would be much simpler to transform the ACE/Jet proprietary MID()
expression into the Standard SQL SUBSTRING
.
Note that you need to test the text's length to avoid a nasty error e.g. when testing the currently-accepted answer (by King Avitus using the LEFT()
expression) 'as is' via OLE DB on a zero-length string I get the error, "Data provider or other service returned an E_FAIL status" which isn't very helpful :(
I suggest using ACE/Jet's IIF()
expression (which, again, is easily transformed into Standard SQL's CASE
expression) to test for a length zero-length string:
SELECT column_1,
MID(column_1, 1, IIF(LEN(column_1) = 0, 0, LEN(column_1) - 1))
AS column_1_truncated
FROM (
SELECT DISTINCT 'ab' AS column_1 FROM Calendar
UNION ALL
SELECT DISTINCT 'a' FROM Calendar
UNION ALL
SELECT DISTINCT '' FROM Calendar
UNION ALL
SELECT DISTINCT NULL FROM Calendar
) AS MyTable;