These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

sql select statement

lucianopilla
Registered: Oct 18 2007
Posts: 76
Answered

hello, i've a problem with a strek value into a selet statement;
this is the code for slection:
var SQLString = 'SELECT Ragione_sociale as codicefo FROM "Ordini" WHERE Fornitore = +"Fedex";';
is there a problem with code, i don't understnd because it doesn't work.
If i replace strek with a number it works.
var SQLString = 'SELECT Ragione_sociale as codicefo FROM "Ordini" WHERE Fornitore = 12';
Anybody have some suggest about? thanks

Adding intelligence to documents

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
There is an error in your string declaration.

Is "Fedex" a variable that contains the number 12? if it is then the statement should be written with the variable outside the quotes, like this:

var SQLString = 'SELECT Ragione_sociale as codicefo FROM "Ordini" WHERE Fornitore = ' + Fedex;

You can see what your string looks like by running the code in the console window. Always do this during code development so you can see what's going on. Here's an article on using the console window:

http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/javascript_console/

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

lucianopilla
Registered: Oct 18 2007
Posts: 76
hello thomp, i'll try to be more clear about my problem. i've problem with a streak variable in a select statement.

var codicefornitore = "people";
var SQLString = 'Select Ragione_sociale as codicefo from "Ordini" where id='+codicefornitore;

if a assign a number into a variable i haven't problem but when i assign a streak like "people" the statement selection doesn't work. I think there's a problem with sintax, cuold you suggest me the right way to follow?
i hope to be more clear. Regards

Adding intelligence to documents

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
This really isn't an Acrobat JavaScript issue, but rather an SQL statement construction issue. The constructs you have available for writing an SQL are pretty clear. Get an SQL reference, perferably one for your specific database type. Then experiment with accessing the DB from the console window until you find the syntax that will work for you.

I suspect that in order to filter for streaks you'll need a little more intelligence i the query.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

lucianopilla
Registered: Oct 18 2007
Posts: 76
I'd like to know how i can pass a streak variable into a select statement. if i put the strek value directli in the statemet it's work perfectly but if i try to pass it trough a variable it doesn't work. what's the matter?

var SQLString = "SELECT Ordini.Ragione_sociale AS codicefo FROM Ordini WHERE Ordini.Fornitore='SIM1';"

Adding intelligence to documents

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Ok, you're previous statment using the +codicefornitore variable did not include quotes. This is the issue. In fact, in your first post you used a number. When posting you need to be very clear about the details of what you want to do.

Try this.
var SQLString = "SELECT Ordini.Ragione_sociale AS codicefo FROM Ordini WHERE Ordini.Fornitore='" + codicefornitore + "';"
Notice how this line of code includes the single quote around the value provided by the variable. This tells the SQL engine that value is a string.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

lucianopilla
Registered: Oct 18 2007
Posts: 76
thanks thomp,
now it works perfectly.
Best regards

Adding intelligence to documents