triming via sql statement?

D

djc

is there an sql function I can use to return only the first 20 characters of
a field? Basically I am looking for an SQL equivalent to the VBA Left()
function.

anyone?
 
M

Mike Painter

djc said:
is there an sql function I can use to return only the first 20 characters of
a field? Basically I am looking for an SQL equivalent to the VBA Left()
function.

anyone?

In Access you would use Left or Mid.
If linked to an MSFT SQL database then you use the equivalent of Mid and the
name eludes me. You'll find it in the SQL on line books.
 
W

Wendy P.

Hey, you're in luck...I just asked this question last week
and it worked for me!

Use the Left function:

Example:

Left([Table.Field], 50)

or
if all else fails you can go into your database and create
a new query where you limit that field to 50.

Here's my working code...hope it helps! :)
(I used the new "trimmed" field name "shortdesc" in my query.)


SELECT Products.Category, Products.ProductType,
Products.ProductName, Left([Products.Description],225) AS
shortdesc
FROM Products
WHERE Products.Category LIKE '%Specials%'
ORDER BY Products.ProductType DESC , Products.ProductName;
 
H

HSalim

substring

Mike Painter said:
characters

In Access you would use Left or Mid.
If linked to an MSFT SQL database then you use the equivalent of Mid and the
name eludes me. You'll find it in the SQL on line books.
 
D

djc

is it only available in T-SQL? Not access SQL?

Van T. Dinh said:
If you are talking about MS-SQLServer, then there is a
Left() function in T-SQL of exactly the same syntax as VBA
Left().

Check BOL.

HTH
Van T. Dinh
MVP (Access)
 
D

djc

Thanks.

Mike Painter said:
characters

In Access you would use Left or Mid.
If linked to an MSFT SQL database then you use the equivalent of Mid and the
name eludes me. You'll find it in the SQL on line books.
 
D

djc

Thanks.

Wendy P. said:
Hey, you're in luck...I just asked this question last week
and it worked for me!

Use the Left function:

Example:

Left([Table.Field], 50)

or
if all else fails you can go into your database and create
a new query where you limit that field to 50.

Here's my working code...hope it helps! :)
(I used the new "trimmed" field name "shortdesc" in my query.)


SELECT Products.Category, Products.ProductType,
Products.ProductName, Left([Products.Description],225) AS
shortdesc
FROM Products
WHERE Products.Category LIKE '%Specials%'
ORDER BY Products.ProductType DESC , Products.ProductName;

-----Original Message-----
is there an sql function I can use to return only the first 20 characters of
a field? Basically I am looking for an SQL equivalent to the VBA Left()
function.

anyone?


.
 
V

Van T. Dinh

Sorry, misunderstood your question.

Yes, you can use the VBA Left() function in Access / JET SQL.
 
T

Tom Ellison

Dear DJC:

There is no such thing as "Access SQL". Access comes with your choice
of two database engines, Jet, and MSDE. Jet was formerly the only
choice, so some think of it as being the "native" engine for Access.

Fortunately, both Jet and MSDE use the same syntax for the Left()
function you want, so the same advice works for both. For other
functions, this may not hold true.

is it only available in T-SQL? Not access SQL?

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts
 
D

djc

thanks.

Tom Ellison said:
Dear DJC:

There is no such thing as "Access SQL". Access comes with your choice
of two database engines, Jet, and MSDE. Jet was formerly the only
choice, so some think of it as being the "native" engine for Access.

Fortunately, both Jet and MSDE use the same syntax for the Left()
function you want, so the same advice works for both. For other
functions, this may not hold true.



Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top