• Welcome, Guest. Please login.
 
July 10, 2020, 01:31:01 am

News:

Welcome to the SQLitening support forums!


Recent posts

Pages 1 2 3 4 5 ... 10
21
You've got Questions? We've got Answers! / Database locked in local mode ...
Last post by Fim - December 17, 2019, 09:17:34 am
I am building a smaller ERP system with Powerbasic and SQLitening. It works as it should when I run in Remote mode. But when I run in Local mode I get "Database locked" every now and then. It does not appear to be a systematic error. Does anyone have a tip where to look for the error?
/Fim W.
22
You've got Questions? We've got Answers! / Re: Debtors List
Last post by Fredrick Ughimi - December 13, 2019, 06:25:41 am
Hello CJ,

>>Call slSelAry (or slSel once.)

I still will like to make yours work for me.
23
You've got Questions? We've got Answers! / Re: Debtors List
Last post by Fredrick Ughimi - December 13, 2019, 06:22:42 am
Hello Bern,

 >>Maybe your client's system has a different (older) version of SQLite .dll installed?

Yeah that was the problem. Installed the latest version for the client and the error vanished. Thanks.
24
You've got Questions? We've got Answers! / Re: Debtors List
Last post by Bern Ertl - December 11, 2019, 02:08:09 pm
Hi Fred, glad the solution worked for you.  :)

Quote from: Fredrick Ughimi on December 11, 2019, 07:17:56 am...
Aside: Is it possible to get the:

1 = near ""WITH": syntax error

on one system and not get it on another system? One of my clients had this error, but it worked fine on my system.

Positive error message number is SQLite error msg, not SQLitening.  Maybe your client's system has a different (older) version of SQLite .dll installed? 
25
You've got Questions? We've got Answers! / Re: Debtors List
Last post by Fredrick Ughimi - December 11, 2019, 07:56:43 am
Hi CJ,

I tried your code directly against my database. It compiled and ran without showing any result.

#COMPILE EXE
#DIM ALL

#INCLUDE "sqlitening.inc"
FUNCTION PBMAIN () AS LONG

 slopen "HospitalProDB.db3","C"

 LOCAL sData() AS STRING

 slselary " select HospitalNo,SUM(Amount-Discount), 'tblBill' from tblBill group by HospitalNo" +_
          " UNION" +_
          " select HospitalNo,SUM(SellingPrice*Quantity-Discount),'tblCashSales' from tblCashSales group by HospitalNo" +_
          " UNION" +_
          " select HospitalNo,SUM(Amount),  'tblPayments' from tblPayments group by HospitalNo",sData()

 slselary " select HospitalNo,SUM(Amount-Discount), 'tblBill' from tblBill  group by HospitalNo     UNION "  +_
          " select HospitalNo,SUM(SellingPrice * Quantity  - Discount),'tblCashSales' from tblCashSales  group by HospitalNo UNION "  +_
          " select HospitalNo,SUM(Amount),  'tblPayments' from tblPayments group by HospitalNo",sData()

 'without temp table
 LOCAL x,linecounter AS LONG
 DIM hospital(999) AS LONG
 DIM sArray(999)   AS STRING
 FOR x = 1 TO UBOUND(sdata,2)
  hospital(VAL(sdata(1,x))) += VAL(sdata(2,x)) 'combine amounts in column2
 NEXT
 sArray(0) = "Hospital  Amount"  'optional heading
 FOR x = 1 TO UBOUND(hospital)   'hospital 1 to ?
  IF hospital(x) THEN            'if hospital <> 0
   INCR linecounter
   sArray(linecounter) = USING$("#&##.##",x,$TAB,hospital(x)*.01)
  'sArray(linecounter) = FORMAT$(x) + $TAB + USINg$("##.##",hospital(x)*.01)
  END IF
 NEXT
 REDIM PRESERVE sArray(linecounter)
 ? JOIN$(sArray(),$CR),,"Balances"

END FUNCTION


I tried again using DDOC this time and discovered I could retrieve the balances.

#COMPILE EXE
#DIM ALL
#INCLUDE "sqlitening.inc"
#INCLUDE "ddoc_p32.inc"

'DDOC
'  Needed Color Constants (Vb compatible)
'---------------------------------------------------------------------------
%vbBlack = &H0&
%vbRed = &HFF&
%vbGreen = &HFF00&
%vbYellow = &HFFFF&
%vbBlue = &HFF0000
%vbMagenta = &HFF00FF
%vbCyan = &HFFFF00
%vbWhite = &HFFFFFF
%vbGrey = &HC0C0C0
%LIGHT_SHADE = &HE0E0E0

FUNCTION PBMAIN () AS LONG

   slOpen ("HospitalProDB.db3", "C")

   ReportDebtors

END FUNCTION

FUNCTION PBDate(sDate AS STRING) AS STRING
     'MM-dd-yyyy to dd-MM-yyyy

     FUNCTION = MID$(sDate,4,2) & "-" & MID$(sDate,1,2) & "-" & MID$(sDate,7,4)

END FUNCTION

FUNCTION NigeriaDate(sDate AS STRING) AS STRING
     'yyyy-MM-dd  to dd-MM-yyyy
     FUNCTION = MID$(sDate,9,2) & "-" & MID$(sDate,6,2) & "-" & MID$(sDate,1,4)

END FUNCTION

FUNCTION SQLiteDate(sDate AS STRING) AS STRING
     'From dd-MM-yyyy To yyyy-MM-dd

     FUNCTION = MID$(sDate,7,4) & "-" & MID$(sDate,4,2) & "-" & MID$(sDate,1,2)

END FUNCTION

FUNCTION ReportDebtors() AS LONG
      LOCAL dbHandle&, LineSpacing!,iHandle%,Row!,TopMargin!,PageSize!,PageNumber&
      LOCAL detailline AS ASCIIZ * 200
      LOCAL SNo AS LONG
      LOCAL lTotalRecords&
      LOCAL dTotalAmount AS DOUBLE
      LOCAL dNetAmount AS DOUBLE
      LOCAL s AS STRING
      LOCAL dTotalDebts, dTotalBill, dTotalPayment AS DOUBLE

      LineSpacing = .2
      TopMargin   = .5
      PAGESIZE    = 10

      ihandle% = dpStartDoc(0,"Mega-Net HospitalPro - Debtors Report","",%DDOC_INCH, %DDOC_PAPER_A4, %DDOC_PORTRAIT, %DDOC_SYSTEM_DEFAULT, %DDOC_BIN_AUTO OR %DDOC_ALLOWSMTP OR %DDOC_ALLOWSAVE OR %DDOC_ZOOMFIT)
      IF ihandle < 1 THEN
           MSGBOX "Could not StartDoc. Error number" + STR$(Ihandle)
           GOTO EndProgram
      END IF

      dpSetTabs iHandle, "L.5W1 L1.0W1 L2.5W3 L5.5W1 L6.5W1 L7.5W1"

      ROW = PAGESIZE                            'force new heading

    slSEL " select HospitalNo,SUM(Amount-Discount), 'tblBill' from tblBill group by HospitalNo" +_
          " UNION" +_
          " select HospitalNo,SUM(SellingPrice*Quantity-Discount),'tblCashSales' from tblCashSales group by HospitalNo" +_
          " UNION" +_
          " select HospitalNo,SUM(Amount),  'tblPayments' from tblPayments group by HospitalNo"

   slSEL " select HospitalNo,SUM(Amount-Discount), 'tblBill' from tblBill  group by HospitalNo UNION "  +_
          " select HospitalNo,SUM(SellingPrice * Quantity  - Discount),'tblCashSales' from tblCashSales group by HospitalNo UNION "  +_
          " select HospitalNo,SUM(Amount),  'tblPayments' from tblPayments group by HospitalNo"


      DO WHILE slGetRow()

        IF ROW => PAGESIZE THEN
           IF PageNumber THEN      'If first page don't need a new page
              dpNewPage iHandle%,  %ddoc_PAPER_A4, %DDOC_PORTRAIT, %DDOC_BIN_AUTO
           END IF
           INCR PageNumber
           LOCAL hjpg AS LONG
             ''hjpg = dpAddGraphic(ihandle%, VD_App.Path & "Logo.jpg")
             IF hjpg THEN
                dpDrawGraphic ihandle%, hjpg,3.5,.2,2,1
             END IF

           dpText iHandle%, .5,TopMargin,  %DDOC_Left,"Page: "+ STR$(PageNumber)+""
           'dpText iHandle%, .5,TopMargin + .2,  %DDOC_Left,"Total Records: "+ Str$(lTotalRecords&)+""
           dpText iHandle%, 6,TopMargin,  %DDOC_Left,"Date: "+ PBDate(DATE$)+""
           dpText iHandle%, 6,TopMargin +.2,  %DDOC_Left,"Time: "+ TIME$+""
           ROW =TopMargin + LineSpacing * 4
           dpFont ihandle%, %DDOC_FONTNORMAL + %DDOC_FONTBOLD, 12, %vbGreen, "Arial"
           dpText ihandle, 4.25, 1.1, %DDOC_CENTER, "Ameso Hospital" ''& gName
           dpFont ihandle%, %DDOC_FONTNORMAL + %DDOC_FONTBOLD, 12, %vbRed, "Arial"
           dpText IHandle%, 4.25, 1.4, %DDOC_CENTER, "Ogudu, Lagos" ''& gAddress
           dpFont ihandle%, %DDOC_FONTNORMAL + %DDOC_FONTUNDERLINE + %DDOC_FONTBOLD, 12, %vbBlack, "Arial"
           dpText IHandle%, 4.25, 1.7, %DDOC_CENTER, "Debtors Report"
           'dpText IHandle%, 6.25, 2.0, %DDOC_CENTER, "Date Range:  " & sFrom  & " To " & sTo
           'dpText IHandle%, .5, 2.3, %DDOC_Left, "Total Debts: " & Format$(dTotalDebts, "#,.00")
           dpFont ihandle%, %DDOC_FONTNORMAL + %DDOC_FONTUNDERLINE + %DDOC_FONTBOLD, 9, %vbBlack, "Arial"
           dpTabText iHandle%, ROW + 0.9, "SNo" + $TAB + "HospitalNo" + $TAB + "Surname" + $TAB + "Othernames" + $TAB + "Balance"
           dpFont ihandle%, %DDOC_FONTNORMAL, 8, %vbBlack, "San Serif"
           ROW =  ROW + LineSpacing * 2
        END IF

        INCR SNo
        DetailLine$ =  _
          STR$(SNo) + $TAB + _
          slFN("HospitalNo") + $TAB + _
          slFN("Amount")

          dpTabText iHandle%, ROW + 0.7, DetailLine
          ROW = ROW + LineSpacing                    'increment line counter

      LOOP

      dpEndDoc iHandle%, %DDOC_END_VIEW + %DDOC_END_PRINT
    EndProgram:
    END FUNCTION
26
You've got Questions? We've got Answers! / Re: Debtors List
Last post by Fredrick Ughimi - December 11, 2019, 07:17:56 am
Hello Bern,

>>Then this should work (adjust table names to match your code):

This worked. I am going to test further in the days to come.

Thanks a million.

s=  "WITH"
        s+="   TempT1(TT1HospitalNo,Surname, Othernames,TT1Total) AS (SELECT HospitalNo, Surname, Othernames, Amount - Discount"
        s+="     FROM tblBill),"
        s+="   TempT2(TT2HospitalNo,Name,TT2Total) AS (SELECT tblCashSales.HospitalNo, Name, Quantity * SellingPrice - Discount"
        s+="     FROM tblCashSales),"
        s+="   SumT1( ST1HospitalNo, ST1Total) AS (SELECT TT1HospitalNo, TOTAL( TT1Total)"
        s+="     FROM TempT1 GROUP BY TT1HospitalNo),"
        s+="   SumT2( ST2HospitalNo, ST2Total) AS (SELECT TT2HospitalNo, TOTAL( TT2Total)"
        s+="     FROM TempT2 GROUP BY TT2HospitalNo),"
        s+="   SumT3(ST3HospitalNo, Surname, Othernames, ST3Total) AS (SELECT tblPayments.HospitalNo, Surname, Othernames, TOTAL(Amount)"
        s+="     FROM tblPayments GROUP BY tblPayments.HospitalNo)"
        s+=" SELECT tblBioData.HospitalNo, tblBioData.Surname, tblBioData.Othernames, ST1Total + ST2Total - ST3Total"
        s+="   FROM tblBioData"
        s+="   LEFT OUTER JOIN SumT1 ON tblBioData.HospitalNo = ST1HospitalNo"
        s+="   LEFT OUTER JOIN SumT2 ON tblBioData.HospitalNo = ST2HospitalNo"
        s+="   LEFT OUTER JOIN SumT3 ON tblBioData.HospitalNo = ST3HospitalNo"
        s+="   WHERE ST1Total + ST2Total > ST3Total"           

Aside: Is it possible to get the:

1 = near ""WITH": syntax error

on one system and not get it on another system? One of my clients had this error, but it worked fine on my system.
27
You've got Questions? We've got Answers! / Re: Debtors List
Last post by Bern Ertl - December 10, 2019, 04:26:00 pm
Quote from: Fredrick Ughimi on December 10, 2019, 01:56:25 pm...
Yes, there is a master table I called tblBioData which contains the HospitalNo, Surname, Othernames, etc.
...

Then this should work (adjust table names to match your code):s=  "WITH"
s+="   TempT1(TT1Surname,TT1Total) AS (SELECT Surname1, Amount1 - Discount"
s+="     FROM T1),"
s+="   TempT2(TT2Surname,TT2Total) AS (SELECT Surname2, Quantity * SellingPrice - Discount"
s+="     FROM T2),"
s+="   SumT1( ST1Surname, ST1Total) AS (SELECT TT1Surname, TOTAL( TT1Total)"
s+="     FROM TempT1 GROUP BY TT1Surname),"
s+="   SumT2( ST2Surname, ST2Total) AS (SELECT TT2Surname, TOTAL( TT2Total)"
s+="     FROM TempT2 GROUP BY TT2Surname),"
s+="   SumT3( ST3Surname, ST3Total) AS (SELECT Surname3, TOTAL( Amount3)"
s+="     FROM T3 GROUP BY Surname3)"
s+=" SELECT ST3Surname, ST1Total + ST2Total - ST3Total"
s+="   FROM tblBioData"
s+="   LEFT OUTER JOIN SumT1 ON tblBioData.Surname = ST1Surname"
s+="   LEFT OUTER JOIN SumT2 ON tblBioData.Surname = ST2Surname"
s+="   LEFT OUTER JOIN SumT3 ON tblBioData.Surname = ST3Surname"
s+="   WHERE ST1Total + ST2Total > ST3Total"
28
You've got Questions? We've got Answers! / Re: Debtors List
Last post by Fredrick Ughimi - December 10, 2019, 02:04:48 pm
Hello CJ,

>>The dummy columns t1,t2,t3 are required to get the correct results.  Please test!

I will test it as soon as I am with my computer. Thanks a lot.
29
You've got Questions? We've got Answers! / Re: Debtors List
Last post by Fredrick Ughimi - December 10, 2019, 01:56:25 pm
Hello Bern,

>>That's because I used INNER JOINs. You can use LEFT OUTER JOINS if you want results from partial matches, but even so, the table referenced after FROM will control the results set, so the results only return for records in that table. 

Thank you for your explanations.


>>Like I said previously, if you have a fourth table that contains a master list of the Surnames/HopsitalNos, you can use that as the FROM reference and LEFT OUTER JOIN the 3 "SUM" tables from the WITH clause and get a full result set.


Yes, there is a master table I called tblBioData which contains the HospitalNo, Surname, Othernames, etc.

I will follow your instructions and see how it goes. Thanks a lot.


30
You've got Questions? We've got Answers! / Re: Debtors List
Last post by Bern Ertl - December 10, 2019, 11:54:23 am
Quote from: Fredrick Ughimi on December 10, 2019, 10:14:35 am...
>>Bern routine results: 1 payment record must exist to return results for a client

I also noticed that all three tables needs to have data for a client to return results for that client.

That's because I used INNER JOINs. You can use LEFT OUTER JOINS if you want results from partial matches, but even so, the table referenced after FROM will control the results set, so the results only return for records in that table. 

Like I said previously, if you have a fourth table that contains a master list of the Surnames/HopsitalNos, you can use that as the FROM reference and LEFT OUTER JOIN the 3 "SUM" tables from the WITH clause and get a full result set.
Pages 1 2 3 4 5 ... 10