× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



What happens when you do With adjust as (...)
Select * from Adjust;

Do you get a valid number?



On Sat, Feb 27, 2021, 8:36 PM Don Brown via MIDRANGE-L <
midrange-l@xxxxxxxxxxxxxxxxxx> wrote:

Thank Alan but same error;

See my testing;

select sum(ntramt) from dktntrpf where ntrnpd = 3913 and ntrtty = 'UDD';
<=== This works and gives the result

select sum(ntramt) from dktntrpf where ntrnpd = 3913 and ntrtty = 'ADJ';
<=== This works and gives the result

Select npdsdt, npdedt, npdamt, npdsts, npdtno, npdabl, npdnph, npdnpd,
nphnab
-- Cast(npdamt + Adjust - amount As Decimal(11,2)) <=== I
commented the cast out and this works returning one row.
from dktnphpf, dktnpdpf
where nphcoy = 1 and nphnab = 'ND0001' and nphnph = npdnph;

With Amount as (select sum(ntramt) from dktntrpf where ntrnpd = 3913 and
ntrtty = 'UDD'), -- <=== But this fails with the error below.
Adjust as (select sum(ntramt) from dktntrpf where ntrnpd = 3913 and ntrtty
= 'UDD')
Select npdsdt, npdedt, npdamt, npdsts, npdtno, npdabl, npdnph, npdnpd,
nphnab,
Cast(npdamt + adjust - amount As Decimal(11,2))
from dktnphpf, dktnpdpf
where nphcoy = 1 and nphnab = 'ND0001' and nphnph = npdnph;


Error:
SQL State: 42703
Vendor Code: -206
Message: [SQL0206] Column or global variable ADJUST not found.


Which is the same error I had originally ?






From: "Alan Campin" <alan0307d@xxxxxxxxx>
To: "Midrange Systems Technical Discussion"
<midrange-l@xxxxxxxxxxxxxxxxxx>
Date: 28/02/2021 02:23 PM
Subject: Re: SQL - Using result fields in a calculation
Sent by: "MIDRANGE-L" <midrange-l-bounces@xxxxxxxxxxxxxxxxxx>



With Amount as (select sum(ntramt) from dktntrpf where ntrnpd = 3913 and
ntrtty =
'UDD'),
Adjust as (select sum(ntramt) from dktntrpf where ntrnpd = 3913 and ntrtty
=
'UDD')
Select npdsdt, npdedt, npdamt, npdsts, npdtno, npdabl, npdnph, npdnpd,
nphnab,
Cast(npdamt + adjust - amount As Decimal(11,2))
from dktnphpf, dktnpdpf
where nphcoy = 1 and nphnab = 'ND0001' and nphnph = npdnph;

The cast is not really needed but I like to define the type and size of
any
variable I define.

I would recommend for testing that you test in pieces.

First

With Amount as (...)
Select * from amount;

If that works add the next piece and see that works. If both work add the
last piece,

That way you see if there is some other error in the code
Also I note you don't have a join clause. Deliberate?




On Sat, Feb 27, 2021, 6:50 PM Don Brown via MIDRANGE-L <
midrange-l@xxxxxxxxxxxxxxxxxx> wrote:

Thank you for your reply Alan.

Would you be able to share an example as i have not used CTE's

Thanks





From: "Alan Campin" <alan0307d@xxxxxxxxx>
To: "Midrange Systems Technical Discussion"
<midrange-l@xxxxxxxxxxxxxxxxxx>
Date: 28/02/2021 12:47 PM
Subject: Re: SQL - Using result fields in a calculation
Sent by: "MIDRANGE-L" <midrange-l-bounces@xxxxxxxxxxxxxxxxxx>



Why not use CTE's. Much simpler code.



On Sat, Feb 27, 2021, 6:33 PM Don Brown via MIDRANGE-L <
midrange-l@xxxxxxxxxxxxxxxxxx> wrote:

Hi,

I have the following SQL

select npdsdt, npdedt, npdamt, npdsts, npdtno, npdabl, npdnph,
npdnpd,
nphnab,
(select sum(ntramt) from dktntrpf where ntrnpd = 3913 and
ntrtty
=
'UDD') as amount,
(select sum(ntramt) from dktntrpf where ntrnpd = 3913 and
ntrtty
=
'ADJ') as adjust,
npdamt + adjust - amount as avail
from dktnphpf, dktnpdpf
where nphcoy = 1 and nphnab = 'ND0001' and nphnph = npdnph;

I am running it in iACS

It fails indicating the variable "adjust" is not found.

I am obviously not using the correct terms when searching google as I
can't find an example of how to use the results or a sub select.

Any assistance would be appreciated.

Thanks

Don




--
This email has been scanned for computer viruses. Although MSD has
taken
reasonable precautions to ensure no viruses are present in this email,
MSD
cannot accept responsibility for any loss or damage arising from the
use
of
this email or attachments..
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit:



https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.midrange.com_mailman_listinfo_midrange-2Dl&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=Ujx-rkrGSO55h_jypQFfIiHaHA5RwcjZpDDGKfQVwCc&s=20L2tP8BR3TTjEzg0c10Ad7jQh76XEcpmWmubrBNofM&e=


or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at



https://urldefense.proofpoint.com/v2/url?u=https-3A__archive.midrange.com_midrange-2Dl&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=Ujx-rkrGSO55h_jypQFfIiHaHA5RwcjZpDDGKfQVwCc&s=BzwQ8Z6zZDW1xi6KgosG7vR8JYWfOC8x9M1FgI--nMQ&e=

.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription
related
questions.

Help support



https://urldefense.proofpoint.com/v2/url?u=http-3A__midrange.com&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=Ujx-rkrGSO55h_jypQFfIiHaHA5RwcjZpDDGKfQVwCc&s=Mqos72GpQZwTS914dlmKpQuemp8aUx6AAI_uo8tCAgI&e=

by shopping at



https://urldefense.proofpoint.com/v2/url?u=http-3A__amazon.com&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=Ujx-rkrGSO55h_jypQFfIiHaHA5RwcjZpDDGKfQVwCc&s=xQQhRc_hC0zHQcwu9-Yf7G-N9YQK00p02ySMwIttDWQ&e=

with our affiliate
link:



https://urldefense.proofpoint.com/v2/url?u=https-3A__amazon.midrange.com&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=Ujx-rkrGSO55h_jypQFfIiHaHA5RwcjZpDDGKfQVwCc&s=WG23P3IU834Gq8DyPUYVwnt-1cduIhrj4kSbr1oYO88&e=



--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit:



https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.midrange.com_mailman_listinfo_midrange-2Dl&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=Ujx-rkrGSO55h_jypQFfIiHaHA5RwcjZpDDGKfQVwCc&s=20L2tP8BR3TTjEzg0c10Ad7jQh76XEcpmWmubrBNofM&e=


or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at



https://urldefense.proofpoint.com/v2/url?u=https-3A__archive.midrange.com_midrange-2Dl&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=Ujx-rkrGSO55h_jypQFfIiHaHA5RwcjZpDDGKfQVwCc&s=BzwQ8Z6zZDW1xi6KgosG7vR8JYWfOC8x9M1FgI--nMQ&e=

.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related
questions.

Help support



https://urldefense.proofpoint.com/v2/url?u=http-3A__midrange.com&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=Ujx-rkrGSO55h_jypQFfIiHaHA5RwcjZpDDGKfQVwCc&s=Mqos72GpQZwTS914dlmKpQuemp8aUx6AAI_uo8tCAgI&e=

by shopping at



https://urldefense.proofpoint.com/v2/url?u=http-3A__amazon.com&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=Ujx-rkrGSO55h_jypQFfIiHaHA5RwcjZpDDGKfQVwCc&s=xQQhRc_hC0zHQcwu9-Yf7G-N9YQK00p02ySMwIttDWQ&e=

with our affiliate link:



https://urldefense.proofpoint.com/v2/url?u=https-3A__amazon.midrange.com&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=Ujx-rkrGSO55h_jypQFfIiHaHA5RwcjZpDDGKfQVwCc&s=WG23P3IU834Gq8DyPUYVwnt-1cduIhrj4kSbr1oYO88&e=






--
This email has been scanned for computer viruses. Although MSD has taken
reasonable precautions to ensure no viruses are present in this email,
MSD
cannot accept responsibility for any loss or damage arising from the use
of
this email or attachments..
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit:

https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.midrange.com_mailman_listinfo_midrange-2Dl&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=eXIxBbr3VqJD3wCezEK_IfTQDOF3eRXaDnDWsBJLHnI&s=KvPxmIbyDLIvOeqwhQyme0J7algFXmWnw_-FLwin_Uw&e=

or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at

https://urldefense.proofpoint.com/v2/url?u=https-3A__archive.midrange.com_midrange-2Dl&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=eXIxBbr3VqJD3wCezEK_IfTQDOF3eRXaDnDWsBJLHnI&s=jHqnFTbGo8l_F3OmT1dUdRCehaBRsJtpVhqpl8DCdQc&e=
.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related
questions.

Help support

https://urldefense.proofpoint.com/v2/url?u=http-3A__midrange.com&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=eXIxBbr3VqJD3wCezEK_IfTQDOF3eRXaDnDWsBJLHnI&s=GtT9cT344QFoTUiQEn1NHW5Pfea29C16ibaly0NopVE&e=
by shopping at

https://urldefense.proofpoint.com/v2/url?u=http-3A__amazon.com&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=eXIxBbr3VqJD3wCezEK_IfTQDOF3eRXaDnDWsBJLHnI&s=52Fc7QNlH2uEPsdBipqbXohpmL2BKImcyve9zShef54&e=
with our affiliate
link:

https://urldefense.proofpoint.com/v2/url?u=https-3A__amazon.midrange.com&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=eXIxBbr3VqJD3wCezEK_IfTQDOF3eRXaDnDWsBJLHnI&s=U5GboQ7eE7fQbfH6RJdz3v-e8GdsCTUS6wXY6KPzr5w&e=


--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit:

https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.midrange.com_mailman_listinfo_midrange-2Dl&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=eXIxBbr3VqJD3wCezEK_IfTQDOF3eRXaDnDWsBJLHnI&s=KvPxmIbyDLIvOeqwhQyme0J7algFXmWnw_-FLwin_Uw&e=

or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at

https://urldefense.proofpoint.com/v2/url?u=https-3A__archive.midrange.com_midrange-2Dl&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=eXIxBbr3VqJD3wCezEK_IfTQDOF3eRXaDnDWsBJLHnI&s=jHqnFTbGo8l_F3OmT1dUdRCehaBRsJtpVhqpl8DCdQc&e=
.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related
questions.

Help support

https://urldefense.proofpoint.com/v2/url?u=http-3A__midrange.com&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=eXIxBbr3VqJD3wCezEK_IfTQDOF3eRXaDnDWsBJLHnI&s=GtT9cT344QFoTUiQEn1NHW5Pfea29C16ibaly0NopVE&e=
by shopping at

https://urldefense.proofpoint.com/v2/url?u=http-3A__amazon.com&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=eXIxBbr3VqJD3wCezEK_IfTQDOF3eRXaDnDWsBJLHnI&s=52Fc7QNlH2uEPsdBipqbXohpmL2BKImcyve9zShef54&e=
with our affiliate link:

https://urldefense.proofpoint.com/v2/url?u=https-3A__amazon.midrange.com&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=eXIxBbr3VqJD3wCezEK_IfTQDOF3eRXaDnDWsBJLHnI&s=U5GboQ7eE7fQbfH6RJdz3v-e8GdsCTUS6wXY6KPzr5w&e=





--
This email has been scanned for computer viruses. Although MSD has taken
reasonable precautions to ensure no viruses are present in this email, MSD
cannot accept responsibility for any loss or damage arising from the use of
this email or attachments..
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/midrange-l.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.