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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combine three records to one with a sql select() 1

Status
Not open for further replies.

Koen Piller

Programmer
Jun 30, 2005
841
NL
Hi,
I am facing a complete blackout, it seems, following code, which intents to combine the three records surname,insertion,famname into one record fullname, however somehow my coding is incorrect. Anybody to spot the error?

Code:
lcLetter = 'K'
lcSQL = 'Select district, Alltrim(Alltrim(surname)+' '+Alltrim(insertion))+' '+famname As fullnaam, Id from NAW '+;
	IIF(Empty(m.lcLetter),'','where Substr(surname,1) = "'m.lcLetter)+'" order by 1 into cursor junklist nofilter'

So the cursor should read e.g.
"Koen Piller","1"
"Kyle the Expert","2"


Regards,

Koen
 
What does lcSQL contain after the assignment?

What's actually happening? An error? Nothing returned?

Tamar
 
Hi,

Error: "Command contains unrecognized phrase/keyword"

Regards,

Koen
 
You get this error when executing the lcSQL = ... line, right?
You can't have single quotes within a string delimited by single quotes.

A simplified version of your error:
Code:
lcSQL = 'Select a+' '+b from Table'

This has two string literals in this line:
1. 'Select a+'
2. '+b from Table'

And there is a space in between them. Let's say you had these strings in two variables x and y, then in short your code is:
Code:
lcSQL = x y
Do you see what the parser doesn't see a valid phrase in there? Just because your string separation with a space is so short it doesn't look like the end of the string to you, the parser still strictly interprets the same string delimiter the string starts with as the end. There is no parsing in the way "Oh, the user meant it differently". You start a string with a single quote? Fine, the next single quote the parser encounters is the end of that string. Even if no operator follows, but the next single quote string delimiter is starting the next string, which is a phrase error, the parser will not get back into string mode parsing and mend its interpretation, this is simple and strict.

In general it helps to set up your syntax coloring to show strings red, but in this case, the small gap between two strings will not be noticeable by simple syntax coloring.

There is a simple way to get done with such errors in case of complex code like SQL or HTML, where you likely need to use all of VFPs string delimiters single quote, double quote and square brackets within the string: Use TEXT..ENDTEXT

Bye, Olaf.

Olaf Doschke Software Engineering
 
Olaf,
Thanks, indeed with
Code:
Text...Endtext
no problem it works.
Regards,
Koen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top