开发者

how to delete everything after a blank space in access

开发者 https://www.devze.com 2023-02-09 19:43 出处:网络
I have a table->column first-name with values: Juan Manuel l. Richard Wit I\'m trying to do a query that return

I have a table->column first-name with values:

Juan
Manuel l.
Richard Wit

I'm trying to do a query that return

开发者_运维技巧
Juan
Manul
Richard

I want to eliminate after a space.


Assuming you want SQL, try

SELECT MID(name  + " a", 1, INSTR(name + " a", " ")-1) AS FirstName FROM myTable

In VBA it would be similar, since Mid() and InStr() work exactly the same as in Access-SQL


Really, though, it would be better to just store first and last name in separate fields so you don't have to do this sort of finagling in the SQL.


SELECT Left([First-Name], InStr([First-Name] & ' ', ' ') - 1) As CleanFirstName
FROM table

Keep in mind that running this will be inefficient since you will be executing VBA functions against every record in your query. Depending on how you are using this, you may want to have the query return the full field and do the processing after the fact.

0

精彩评论

暂无评论...
验证码 换一张
取 消