View Full Version : Help with a Split Query


reens80
12-19-2007, 03:12 AM
Hi All,

Hope you can help, it’s been a while since I have used Access, and I am using 2007.

I am trying to split out Postcodes to remove the last 2 characters, i.e.

LE12 6YU becomes LE12 6 (NewPostCode)
LE5 8YU becomes LE5 8

I set up my query in data set view and then I switch over to SQL view, this is what I have

================================================== ===
SELECT Sample.Postcode, split([Postcode], RIGHT(postcode, 2))(0) AS NewPostCode
FROM Sample;
================================================== ====
When doing this query I get an error saying invalid syntax and it reads the (0) as (0. Or something

Much appreciated,

Guus2005
12-19-2007, 03:27 AM
Not sure what SPLIT in a query does.
You can use it to create an array from a string in VBA.

This is how i would do it:

SELECT Sample.Postcode, LEFT$([Postcode], LEN([postcode])-2) AS NewPostCode
FROM Sample;


HTH:D

reens80
12-19-2007, 03:41 AM
Great, thanks.