Question : Access - Understanding complex querries (matthewspatrick)

Please explain how this query works:  Break it out in parts so that I can see what you are doing.  What does the 1 and -1 mean?

This is my extent of understanding at this point:  A second Last Name field called LNameOnly is created.  Take the original last name field, LName, with specific criteria (What are you looking for here) and replacing it (what are you replacing it with?)

SELECT LName, Replace(IIf(InStr(1, LName, " ") > 0, Left(LName, InStr(1, LName, " ") - 1), LName), ",", "") AS LNameOnly

Thanks!

Answer : Access - Understanding complex querries (matthewspatrick)

If I read it right it looks like it is intended to strip off any surnames like Jr. Sr. III, etc from the original last name field and create a field called last name only that contains only the proper last name.

SELECT LName - selects current last name field

Replace(IIf(InStr(1, LName, " ") > 0 - INSTR will test to see if there are more than 0 spaces(the " ") in the LNAME field  the 1 here means starting from position 1

Left(LName, InStr(1, LName, " ") - 1),  This is the trupart of the IIF. If it finds a space then it is to replace with characters from the last name field up to the point of the space. So if InStr determined there was a space in character 10 then it would replace 9 characters. 10 -1 (theres your -1)

LName), ",", "") AS LNameOnly This is the false part if it finds no spaces then it will replace with the value of the LNAME field.
Random Solutions  
 
programming4us programming4us