Select Query

How do I correct this query using Pervasive SQL?

Original Query:
SELECT "APIBH".* FROM "GLPOST","APIBH" WHERE ("APIBH"."CNTBTCH"=1171) AND ("GLPOST". "DRILLDWNLK" = "APIBH"."CNTBTCH")

Modified Query:
SELECT "APIBH".* FROM "GLPOST","APIBH" WHERE ("APIBH"."CNTBTCH"=1171) AND ("GLPOST". + substring("DRILLDWNLK",7,4) + "= "APIBH"."CNTBTCH")"

I also need to cast "DRILLDWNLK" from a numeric value to a string value first.


jnsimexAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rushShahCommented:
hi try this..

SELECT	APIBH.* 
FROM	GLPOST,APIBH
WHERE	(APIBH.CNTBTCH=1171) AND (substring(Convert(VARCHAR(Max),GLPOST.DRILLDWNLK),7,4) = APIBH.CNTBTCH)

Open in new window

0
jnsimexAuthor Commented:
hi rushShah,

I get an error when i try to execute the query

SELECT  APIBH.*  
FROM    GLPOST,APIBH
WHERE   (APIBH.CNTBTCH=1171) AND (substring(Convert(VARCHA(Max),GLPOST.DRILLDWNLK),7,4) = APIBH.CNTBTCH)
Some error(s) encountered while executing SQL statement(script).
0
SharathData EngineerCommented:
what about this?
SELECT apibh.* 
FROM   glpost, 
       apibh 
WHERE  (apibh.cntbtch = 1171) 
       AND (Substring(Convert(VARCHAR(10),glpost.drilldwnlk),7, 
                      4) = apibh.cntbtch)

Open in new window

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

jnsimexAuthor Commented:
Pervasive doesnt like the second parameter for Convert

ODBC Error: SQLSTATE = 37000, Native error code = 0
The second parameter glpost for CONVERT is invalid.
0
LowfatspreadCommented:
try

SELECT "APIBH".* FROM "GLPOST","APIBH"
WHERE ("APIBH"."CNTBTCH"=1171)
AND  substring(Cast("GLPOST"."DRILLDWNLK" as char(30)),7,4) = "APIBH"."CNTBTCH"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SharathData EngineerCommented:
try with CAST as Lowfatspread suggested.
0
Anthony PerkinsCommented:
Please refrain from including the SQL Server 2005 Zone for Pervasive questions.  They do not apply.
0
jnsimexAuthor Commented:
I still get an syntax using lowfatspread has suggested:

ODBC Error: SQLSTATE = 37000, Native error code = 0
Syntax Error: SELECT "APIBH".* FROM "GLPOST","APIBH"
 WHERE ("APIBH"."CNTBTCH"=1171)
 AND  substring(Cast("GLPOST"."DRILLDWNLK" as<< ??? >> char(30)),7,4) = "APIBH"."CNTBTCH"

I tried to isolate the "DRILLDWNLK" value using substring and concactenating it with the "GLPOST" but i still get the same syntax error.

ODBC Error: SQLSTATE = 37000, Native error code = 0
Syntax Error: SELECT "APIBH".* FROM "GLPOST","APIBH"
 WHERE ("APIBH"."CNTBTCH"=1171)
 AND  "GLPOST." + substring(Cast(DRILLDWNLK as<< ??? >> char(30)),7,4) +" = "APIBH"."CNTBTCH""
0
LowfatspreadCommented:
you cant "isolate" the tablename/alias from the column name expression that doesn't make any sense to the syntax of sql!

why do you have the as<< ??? >>  in the middle of the code???
that isn't what i posted


try
AND  substring(Cast("GLPOST"."DRILLDWNLK" as char20),7,4) = "APIBH"."CNTBTCH"
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.