Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Exact

Status
Not open for further replies.

audiopro

Programmer
Apr 1, 2004
3,165
GB
I have this query which works OK unless the vars; website and loaded site are similar.
Code:
SELECT WEBSITE,FILENAME,LOCAL,REMOTE FROM FILES WHERE ALLTRIM(WEBSITE) = ALLTRIM(LOADEDSITE) ORDER BY FILENAME INTO ARRAY RESULTS

In the 'Website' field of the 'Files' table, I have similar entries for 2 distinct websites, one is 'webforms' and the other is 'webforms2u'.
The problem is, the files for both are selected when I search for 'webforms.
I have tried SET EXACT both on and off but it makes no difference - what am I doing wrong?


Keith
 
Have you tried:
Code:
WHERE ALLTRIM(WEBSITE) == ALLTRIM(LOADEDSITE)  && Note double equal sign

Also, depending on who and how the Website field was populated, you might also need to make it Not case-sensitive
Code:
ALLTRIM(UPPER(WEBSITE)) == ALLTRIM(UPPER(LOADEDSITE))

Good Luck,
JRB-Bldr

 
Looks like a table for your FTP syncing.

Why keep it so flat? Have a websites table and store a websiteid in the files table, then determine the websiteid of the loadedsite as loadedsiteid and you'd also have no string comparison.

I'm not saying you can circumvent any string comparison in queries by normalizing them into a separate table, but as a side effect here this would solve that problem, too. Overall with normalized data you more often filter or join by ids, which have no problem with string comparison by vfp, ansi or any other standard or encoding or whatever else might effect the comparsion.

Bye, Olaf.

 
One other thing here that most people miss that could cause performance issues with a large table.

WHERE ALLTRIM(WEBSITE) = ALLTRIM(LOADEDSITE) will not optimized unless ALLTRIM(WebSite) is indexed, which is not advised because it results in variable length keys. A better solution is to index the table on WebSite, then use

WHERE WebSite == PADR(LoadedSite, LEN(WebSite))

Craig Berntson
MCSD, Visual C# MVP,
 
Thanks for the replies.
SET ANSI was the answer.

Olaf, not sure I understand what you mean.
I have a WEBSITES table which contains a field for website name and fields for FTP log in details.
When I select a site for use in the program - var. LOADEDSITE is set to website name.
The search above pulls out the pages and other files from the FILES table.
I could set relations but this has worked OK until I created 2 websites with similar names.

Keith
 
Well, then you're using the website name as primary and foreign key. Using numeric keys will mean you would filter for a number, which hasn't got the string comparison problem.

Selecting a site (eg from a dropdown combobox) you'd see the website name, but select the primary key - an ID, a number, an integer, typically. You would then lookup that integer elsewhere, not the name. There is no problem with similar numbers, as there is with similar names. the where clause would be WHERE WEBSITEID = LOADEDSITEID, with both being integers, and there is no inexact comparison, then, which could bring down files from a seperate website into the result.

It's just a suggestion, as many times currently, about using surrogate keys rather than natural keys. So I'm just adding another advantage of surrogate keys.

Bye, Olaf.



 
Thanks for the explanation - yes it makes perfect sense.
The reason I do it 'my way' is that I often manually edit the file list and it is easier referencing the website name rather than a number.
It all works well, now that I have got the ANSI thing set right.

Keith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top