Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 8 of 8 total
Thread SQL Parsing error..
Mon, May 28 2018 6:34 PMPermanent Link

Ian Branch

Avatar

Hi Team,
I have the following query imported form another DB.
"select JobTickets.jobtype as [Job Type], count(JobTickets.MSN) as [Total Units], count(distinct JobTickets.MSN) as [Unique Units], count(JobTickets.msn)-count(distinct JobTickets.msn) as [Repeats]
from JobTickets JobTickets
where (trim(JobTickets.msn) <> '') and (JobTickets.Date_in >= :StartDate) and (JobTickets.date_in <= :EndDate) and (jobtickets.buscode = :buscode)
group by JobType;"

When I Prepare or Run the query I get an error..
"DBISAM Engine Error # 11949 SQL parsing error - Expected ) but instead found JobTickets in SELECT SQL statement at line 1, column 97"

What is the correct way to make this query work in DBISAM please?

Regards & TIA,
Ian
Tue, May 29 2018 9:17 AMPermanent Link

Fernando Dias

Team Elevate Team Elevate

Ian,

Why is JobTickets refred 2 times after "from" ?

--
Fernando Dias
[Team Elevate]
Tue, May 29 2018 10:33 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Fernando


>Why is JobTickets refred 2 times after "from" ?

He's setting the alias of JobTickes to JobTickets. I don't know why but maybe some systems require the alias rather than it being optional. I doubt it makes much if any difference either way.

Roy
Tue, May 29 2018 10:46 AMPermanent Link

Fernando Dias

Team Elevate Team Elevate


Also, I've found another issue - the TRIM syntax is not correct: it should be TRIM(BOTH ' ' FROM JobTickets.msn)

--
Fernando Dias
[Team Elevate]
Tue, May 29 2018 10:57 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Fernando


>Also, I've found another issue - the TRIM syntax is not correct: it should be TRIM(BOTH ' ' FROM JobTickets.msn)

I ignored that one cos its got a good error message which Ian will see when he sorts out his other problem <VBG>

Roy
Tue, May 29 2018 11:00 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Fernando


As a bit of a chuckle - at least Ian doen't have to worry about null vs ''

Roy




Tue, May 29 2018 2:24 PMPermanent Link

Ian Branch

Avatar

Roy, Fernando,
Yes I saw that one and was aware of the change required.
Regards,
Ian
Wed, May 30 2018 6:28 AMPermanent Link

Fernando Dias

Team Elevate Team Elevate

Ian,

The main issue is the DISTINCT that is not supported in COUNT.
To do what you want you will have to create a temporary table and drop
it after, like this:


DROP TABLE IF EXISTS "Memory\JobTickets_tmp" ;

SELECT
  JobType, Msn,
  COUNT(Msn) AS UnitsByMsn
INTO
  "Memory\JobTickets_tmp"
FROM
  JobTickets
WHERE
  (TRIM(BOTH ' ' FROM Mmsn) <> '') AND
  (JobTickets.Date_in >= :StartDate) AND
  (JobTickets.date_in <= :EndDate) AND
  (jobtickets.buscode = :buscode)
GROUP BY
  JobType, Msn ;

SELECT
  JobType AS [Job Type],
  SUM(UnitsByMsn) AS [Total Units],
  COUNT(UnitsByMsn) AS [Unique Units],
  SUM(UnitsByMsn) - COUNT(UnitsByMsn) AS Repeats
FROM
  "Memory\JobTickets_tmp"
GROUP BY
  JobType;


After closing the resulting Dataset, dont forget to drop the temporary
table "Memory\JobTickets_tmp"

--
Fernando Dias
[Team Elevate]
Image