1. william yau
  2. PowerBuilder
  3. Wednesday, 9 December 2020 07:50 AM UTC

Hi guru

I would like to upgrade my powerbuilder script to 2019 r

I have question about report for outer join 

Powerbuilder 7.0 script as below 

 FROM pldtl ,
 plhdr, sohdr, stock, customer
 WHERE ( plhdr.pl_sysplno = pldtl.pt_sysplno )
and ( pt_syssono *= so_syssono)
 and ( pt_sysstno *= st_sysstno)
 and ( pl_cuno = cu_cuno )
 and ( pt_itemno IS NULL or rtrim(ltrim(pt_itemno))='')

 

I rewrite as below 

from pldtl left outer join stock on pt_sysstno = st_sysstno left outer join sohdr on pt_sysstno = so_syssono,

customer, plhdr

WHERE ( pl_sysplno = pt_sysplno ) and
( pl_cuno = cu_cuno )
and ( pt_itemno IS NULL or rtrim(ltrim(pt_itemno))='')

but when print out show below error message

I would like to ask what problem for my rewrite script

william 

 

 

George Fok Accepted Answer Pending Moderation
  1. Thursday, 17 December 2020 01:09 AM UTC
  2. PowerBuilder
  3. # 1

problem sloved

thanks

Comment
  1. Armeen Mazda @Appeon
  2. Thursday, 17 December 2020 01:41 AM UTC
What was the solution?
  1. Helpful
There are no comments made yet.
mike S Accepted Answer Pending Moderation
  1. Thursday, 10 December 2020 16:49 PM UTC
  2. PowerBuilder
  3. # 2

1.  copy and paste the sql into sql manager and run that.  Does it give the same error?  does it show you where the error is?

2.  what is weird around where you have error information - pl_sysplno ??  the answer is: the comments.  Did you delete the commented code and try it?

       (  datawindows can get confused with anything other than basic sql )

 

3. if you still have problems, then start to reduce the complexity of what you are doing.  within sql manager, replace the select portion with *  ( select * from ..... ) and run it.  Do you get an error?  If NO then the error is in the select portion, if yes, then it is within either the from or the where.  continue this until you find where the problem actually is.

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Thursday, 10 December 2020 03:30 AM UTC
  2. PowerBuilder
  3. # 3

Thank you for showing us the entire SELECT statement, William.

Now, I have several additional questions, and you really need to answer all of them, please.

  1. What version of MS SQL Server are you using?
  2. Is it possible for you to try using SQL Server Native Client 11 instead of 10 (10 is pretty old)?
  3. Does this SELECT statement work correctly if executed from SQL Server Management Studio?
  4. Does this SELECT statement work correctly if executed from the ISQL pane in the PowerBuilder Database Painter?
  5. Would you please show us all of the SQLCA properties you use to connect to this SQL Server database from either the PowerBuilder IDE and your application?

Regards, John

Comment
  1. mike S
  2. Thursday, 10 December 2020 16:54 PM UTC
eh, that sql should work regardless of version or settings. i bet its the comments.

Notice too that the error changed from the original post
  1. Helpful
There are no comments made yet.
william yau Accepted Answer Pending Moderation
  1. Thursday, 10 December 2020 01:15 AM UTC
  2. PowerBuilder
  3. # 4

Miks 

the old 7.0 sql 

SELECT ' ' as cc_tradeterm,
' ' as cc_payterm,
' ' as cc_delivery,
' ' as cc_packing,
' ' as cc_remark,
' ' as cc_destination,
' ' as cc_shipmark,
' ' as cc_lcno,
' ' as cc_bank,
' ' as cc_vessel,
' ' as cc_buyerno,
' ' as cc_aboard,
' ' as cc_portload,
' ' as cc_portdischarge,
' ' as cc_wgross,
' ' as cc_originmat,
' ' as cc_manufacturer,
' ' as cc_picfname,
' ' as cc_stno,
' ' as cc_netamt_text,
' ' as cc_salesname,
' ' as cc_cname,
isnull(st_stno,' ') as st_stno,
isnull(st_desc,' ') as st_desc,
isnull(st_cdesc, ' ') as st_cdesc,
isnull(st_edition, ' ') as st_edition,
isnull(st_isbn, ' ') as st_isbn,
plhdr.pl_sysplno ,
case pl_revision when 0 then pl_plno else pl_plno + ' - ' + convert(varchar, pl_revision) end as pl_plno,
plhdr.pl_cuno ,
plhdr.pl_sconame ,
plhdr.pl_saddr1 ,
plhdr.pl_saddr2 ,
plhdr.pl_saddr3 ,
plhdr.pl_saddr4 ,
plhdr.pl_pldate ,
plhdr.pl_shipdate ,
plhdr.pl_syssino ,
plhdr.pl_payterms ,
plhdr.pl_volunit ,
plhdr.pl_revision ,
plhdr.pl_customf1 ,
plhdr.pl_customf2 ,
plhdr.pl_customf3 ,
plhdr.pl_customf4 ,
plhdr.pl_customf5 ,
plhdr.pl_customf6 ,
plhdr.pl_customf7 ,
plhdr.pl_customf8 ,
plhdr.pl_customf9 ,
plhdr.pl_customf10 ,
plhdr.pl_customf11 ,
plhdr.pl_customf12 ,
plhdr.pl_customf13 ,
plhdr.pl_customf14 ,
plhdr.pl_customf15 ,
plhdr.pl_customf16 ,
plhdr.pl_customf17 ,
plhdr.pl_customf18 ,
plhdr.pl_customf19 ,
plhdr.pl_customf20 ,
plhdr.pl_customf31 ,
plhdr.pl_custom_df1 ,
plhdr.pl_custom_df2 ,
plhdr.pl_custom_nf1 ,
plhdr.pl_custom_nf2 ,
plhdr.pl_custom_mf1 ,
plhdr.pl_custom_mf2 ,
pldtl.pt_sysplno ,
pldtl.pt_seqno ,
pldtl.pt_sysstno ,
pldtl.pt_qty ,
pldtl.pt_desc ,
pldtl.pt_packfromto ,
pldtl.pt_packtot ,
pldtl.pt_packqty ,
pldtl.pt_umno ,
pldtl.pt_wgross ,
pldtl.pt_wnet ,
IsNull(pt_length , 0 ) as pt_length,
IsNull(pt_width , 0 ) as pt_width,
IsNull(pt_height , 0 ) as pt_height,
pldtl.pt_picfname ,
pldtl.pt_shipmark ,
pldtl.pt_printsmondig ,
pldtl.pt_customf1 ,
pldtl.pt_customf2 ,
pldtl.pt_customf3 ,
pldtl.pt_customf4 ,
pldtl.pt_customf5 ,
pldtl.pt_memo ,
pldtl.pt_memo2 ,
pldtl.pt_custom_nf1 ,
pldtl.pt_custom_nf2 ,
pldtl.pt_custom_df1 ,
pldtl.pt_custom_df2 ,
pldtl.pt_sortseqno ,
pldtl.pt_volume ,
pldtl.pt_innerbox ,
pldtl.pt_outerbox,
IsNull(pt_measure_unit, '') as pt_measure_unit,
IsNull(pt_weight_unit, '') as pt_weight_unit,
PL_CONAME,
so_billdate,
so_country,
isnull(so_pono, ' ') as so_pono,
isnull(so_custpono,' ') as so_custpono,
isnull(so_sono, ' ') as so_sono,
0 as cc_si_sino,
pt_fromcar,
pt_tocar,
plhdr.pl_customf29 ,
plhdr.pl_customf30 ,
cu_phone1,
cu_faxno1,
' ' as cf_packing_t,
' ' as cf_shipment_t,
' ' as pl_customf7_t,
' ' as pl_customf8_t,
' ' as pl_customf9_t,
' ' as pl_customf10_t,
' ' as pl_custom_mf1_t,
' ' as pl_custom_mf2_t
FROM pldtl ,
plhdr, sohdr, stock, customer
WHERE ( plhdr.pl_sysplno = pldtl.pt_sysplno )
and ( pt_syssono *= so_syssono)
and ( pt_sysstno *= st_sysstno)
and ( pl_cuno = cu_cuno )
and ( pt_itemno IS NULL or rtrim(ltrim(pt_itemno))='')

 

I revised sql as your suggested 

SELECT ' ' as cc_tradeterm,
' ' as cc_payterm,
' ' as cc_delivery,
' ' as cc_packing,
' ' as cc_remark,
' ' as cc_destination,
' ' as cc_shipmark,
' ' as cc_lcno,
' ' as cc_bank,
' ' as cc_vessel,
' ' as cc_buyerno,
' ' as cc_aboard,
' ' as cc_portload,
' ' as cc_portdischarge,
' ' as cc_wgross,
' ' as cc_originmat,
' ' as cc_manufacturer,
' ' as cc_picfname,
' ' as cc_stno,
' ' as cc_netamt_text,
' ' as cc_salesname,
' ' as cc_cname,
// isnull(st_stno,'') as st_no,
// isnull(st_desc,' ') as st_desc,
// isnull(st_cdesc, ' ') as st_cdesc,
// isnull(st_edition, ' ') as st_edition,
// isnull(st_isbn, ' ') as st_isbn,
plhdr.pl_sysplno ,
case pl_revision when 0 then pl_plno else pl_plno + ' - ' + convert(varchar, pl_revision) end as pl_plno,
plhdr.pl_cuno ,
plhdr.pl_sconame ,
plhdr.pl_saddr1 ,
plhdr.pl_saddr2 ,
plhdr.pl_saddr3 ,
plhdr.pl_saddr4 ,
plhdr.pl_pldate ,
plhdr.pl_shipdate ,
plhdr.pl_syssino ,
plhdr.pl_payterms ,
plhdr.pl_volunit ,
plhdr.pl_revision ,
plhdr.pl_customf1 ,
plhdr.pl_customf2 ,
plhdr.pl_customf3 ,
plhdr.pl_customf4 ,
plhdr.pl_customf5 ,
plhdr.pl_customf6 ,
plhdr.pl_customf7 ,
plhdr.pl_customf8 ,
plhdr.pl_customf9 ,
plhdr.pl_customf10 ,
plhdr.pl_customf11 ,
plhdr.pl_customf12 ,
plhdr.pl_customf13 ,
plhdr.pl_customf14 ,
plhdr.pl_customf15 ,
plhdr.pl_customf16 ,
plhdr.pl_customf17 ,
plhdr.pl_customf18 ,
plhdr.pl_customf19 ,
plhdr.pl_customf20 ,
plhdr.pl_customf31 ,
plhdr.pl_custom_df1 ,
plhdr.pl_custom_df2 ,
plhdr.pl_custom_nf1 ,
plhdr.pl_custom_nf2 ,
plhdr.pl_custom_mf1 ,
plhdr.pl_custom_mf2 ,
pldtl.pt_sysplno ,
pldtl.pt_seqno ,
pldtl.pt_sysstno ,
pldtl.pt_qty ,
pldtl.pt_desc ,
pldtl.pt_packfromto ,
pldtl.pt_packtot ,
pldtl.pt_packqty ,
pldtl.pt_umno ,
pldtl.pt_wgross ,
pldtl.pt_wnet ,
IsNull(pt_length , 0 ) as pt_length,
IsNull(pt_width , 0 ) as pt_width,
IsNull(pt_height , 0 ) as pt_height,
pldtl.pt_picfname ,
pldtl.pt_shipmark ,
pldtl.pt_printsmondig ,
pldtl.pt_customf1 ,
pldtl.pt_customf2 ,
pldtl.pt_customf3 ,
pldtl.pt_customf4 ,
pldtl.pt_customf5 ,
pldtl.pt_memo ,
pldtl.pt_memo2 ,
pldtl.pt_custom_nf1 ,
pldtl.pt_custom_nf2 ,
pldtl.pt_custom_df1 ,
pldtl.pt_custom_df2 ,
pldtl.pt_sortseqno ,
pldtl.pt_volume ,
pldtl.pt_innerbox ,
pldtl.pt_outerbox,
IsNull(pt_measure_unit, '') as pt_measure_unit,
IsNull(pt_weight_unit, '') as pt_weight_unit,
PL_CONAME,
so_billdate,
so_country,
isnull(so_pono, ' ') as so_pono,
isnull(so_custpono,' ') as so_custpono,
isnull(so_sono, ' ') as so_sono,
0 as cc_si_sino,
pt_fromcar,
pt_tocar,
plhdr.pl_customf29 ,
plhdr.pl_customf30 ,
cu_phone1,
cu_faxno1,
' ' as cf_packing_t,
' ' as cf_shipment_t,
' ' as pl_customf7_t,
' ' as pl_customf8_t,
' ' as pl_customf9_t,
' ' as pl_customf10_t,
' ' as pl_custom_mf1_t,
' ' as pl_custom_mf2_t
// FROM pldtl ,
// plhdr, sohdr, stock, customer
// WHERE ( plhdr.pl_sysplno = pldtl.pt_sysplno )
// and ( pt_syssono *= so_syssono)
// and ( pt_sysstno *= st_sysstno)
// and ( pl_cuno = cu_cuno )
// and ( pt_itemno IS NULL or rtrim(ltrim(pt_itemno))='')
from pldtl left outer join stock on pt_sysstno = st_sysstno left outer join sohdr on pt_sysstno = so_syssono,
JOIN customer ON pl_cuno = cu_cuno
JOIN plhdr ON plhdr.pl_sysplno = pldtl.pt_sysplno
where
( pt_itemno IS NULL or rtrim(ltrim(pt_itemno))='')

but run report as fellow mesasge

 

 

would you have any suggestion 

 

William 

 

 

 

Comment
There are no comments made yet.
mike S Accepted Answer Pending Moderation
  1. Wednesday, 9 December 2020 15:08 PM UTC
  2. PowerBuilder
  3. # 5

stock.st_stno  is NOT listed anywhere in your example sql, so we can't tell you what is wrong. 

I like to write the query directly in sql server's sql management tool.  It provides much better errors and will often put you on the sql line that has the error.

-------------------

editorial:

 

I prefer to use JOINs instead of the comma delimited list of tables.  I find comma listed difficult to read and maintain.

so:   ... left outer join sohdr on pt_sysstno = so_syssonocustomer, plhdr

becomes:

... left outer join sohdr on pt_sysstno = so_syssono

JOIN customer ON  pl_cuno = cu_cuno 

JOIN plhdr ON plhdr.pl_sysplno = pldtl.pt_sysplno

Now you can easily see how each table relates to the rest of the sql statement.

Between the use of commas for inner joins, and the use of right outer joins, i generally don't trust what the datawindow writes for sql for anything other than very basic joins.  

 

Comment
  1. mike S
  2. Thursday, 10 December 2020 16:52 PM UTC
i would also replace ISNULL() with coalesce, and CONVERT with CAST since they are standard SQL and work with all databases.
  1. Helpful
  1. Miguel Leeuwe
  2. Thursday, 10 December 2020 17:49 PM UTC
true Mike, but I do think they perform differently. If I'm remembering well, coalesce() is slower. Just to keep it in mind if performance is important.

regards
  1. Helpful
  1. Miguel Leeuwe
  2. Thursday, 10 December 2020 17:50 PM UTC
(I always thought that Convert() was the standard. Never too old ..)
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.