I have the following SQL statement. What I am trying to do is find the longest length address that has a zip+4. I know there may be many address that have the same length. My problem is I am getting addresses that do not have a zip+4. Any help would be greatly appreciated:
SELECT TOP 1 ADDRESS FROM waynedb ;
ORDER BY SQNCNMBR WHERE LEN(ALLTRIM(ADDRESS)) = (SELECT MIN(LEN(ALLTRIM(ADDRESS))) FROM waynedb ;
WHERE LEN(ALLTRIM(ADDRESS)) > 0 AND LEN(ALLTRIM(ZIP4)) > 9)
SELECT TOP 1 ADDRESS FROM waynedb ;
ORDER BY SQNCNMBR WHERE LEN(ALLTRIM(ADDRESS)) = (SELECT MIN(LEN(ALLTRIM(ADDRESS))) FROM waynedb ;
WHERE LEN(ALLTRIM(ADDRESS)) > 0 AND LEN(ALLTRIM(ZIP4)) > 9)