|
What happens when you do With adjust as (...)'UDD';
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 =
'ADJ';<=== This works and gives the result
select sum(ntramt) from dktntrpf where ntrnpd = 3913 and ntrtty =
I<=== This works and gives the result
Select npdsdt, npdedt, npdamt, npdsts, npdtno, npdabl, npdnph, npdnpd,
nphnab
-- Cast(npdamt + Adjust - amount As Decimal(11,2)) <===
andcommented 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
andntrtty = '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
thentrtty =
'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
Ilast 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.npdnpd,
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,
ntrttynphnab,
(select sum(ntramt) from dktntrpf where ntrnpd = 3913 and
=ntrtty
'UDD') as amount,
(select sum(ntramt) from dktntrpf where ntrnpd = 3913 and
=
'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
email,takencan'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
reasonable precautions to ensure no viruses are present in this
theMSD
cannot accept responsibility for any loss or damage arising from
mailinguse
of
this email or attachments..
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L)
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=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__archive.midrange.com_midrange-2Dl&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=Ujx-rkrGSO55h_jypQFfIiHaHA5RwcjZpDDGKfQVwCc&s=BzwQ8Z6zZDW1xi6KgosG7vR8JYWfOC8x9M1FgI--nMQ&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=http-3A__midrange.com&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=Ujx-rkrGSO55h_jypQFfIiHaHA5RwcjZpDDGKfQVwCc&s=Mqos72GpQZwTS914dlmKpQuemp8aUx6AAI_uo8tCAgI&e=
.related
Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription
questions.
Help support
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=
by shopping at
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=
with our affiliate
link:
mailing
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L)
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=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__archive.midrange.com_midrange-2Dl&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=Ujx-rkrGSO55h_jypQFfIiHaHA5RwcjZpDDGKfQVwCc&s=BzwQ8Z6zZDW1xi6KgosG7vR8JYWfOC8x9M1FgI--nMQ&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=http-3A__midrange.com&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=Ujx-rkrGSO55h_jypQFfIiHaHA5RwcjZpDDGKfQVwCc&s=Mqos72GpQZwTS914dlmKpQuemp8aUx6AAI_uo8tCAgI&e=
.related
Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription
questions.
Help support
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=
by shopping at
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=
with our affiliate link:
taken
--
This email has been scanned for computer viruses. Although MSD has
email,reasonable precautions to ensure no viruses are present in this
mailingMSD
cannot accept responsibility for any loss or damage arising from theuse
of
this email or attachments..
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L)
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=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__archive.midrange.com_midrange-2Dl&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=eXIxBbr3VqJD3wCezEK_IfTQDOF3eRXaDnDWsBJLHnI&s=jHqnFTbGo8l_F3OmT1dUdRCehaBRsJtpVhqpl8DCdQc&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=http-3A__midrange.com&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=eXIxBbr3VqJD3wCezEK_IfTQDOF3eRXaDnDWsBJLHnI&s=GtT9cT344QFoTUiQEn1NHW5Pfea29C16ibaly0NopVE&e=.
related
Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription
questions.
Help support
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=by shopping at
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=with our affiliate
link:
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=
--
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__archive.midrange.com_midrange-2Dl&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=eXIxBbr3VqJD3wCezEK_IfTQDOF3eRXaDnDWsBJLHnI&s=jHqnFTbGo8l_F3OmT1dUdRCehaBRsJtpVhqpl8DCdQc&e=
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at
related.
Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription
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=questions.
Help support
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=by shopping at
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=with our affiliate link:
taken
--
This email has been scanned for computer viruses. Although MSD has
MSDreasonable precautions to ensure no viruses are present in this email,
use ofcannot accept responsibility for any loss or damage arising from the
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=ffK7KOhRfCaxgCoIQ9h6qg_M4To0aL35iSCn1n5XJTE&s=691lFPKUJP4D7VxNuy3zKCgYEHB0t1qlbJtAFlrK848&e=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__archive.midrange.com_midrange-2Dl&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=ffK7KOhRfCaxgCoIQ9h6qg_M4To0aL35iSCn1n5XJTE&s=NxWSGPhXZztrjpiJQaE3bwmJ5aM-WW8l9RQSlo15hPc&e=or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at
related
Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription
https://urldefense.proofpoint.com/v2/url?u=http-3A__midrange.com&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=ffK7KOhRfCaxgCoIQ9h6qg_M4To0aL35iSCn1n5XJTE&s=yaZ6kZxYKd0Mob8kmcm7InZWnivLYGiJhwnKbgTTn8U&e=questions.
Help support
https://urldefense.proofpoint.com/v2/url?u=https-3A__amazon.midrange.com&d=DwICAg&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=Kys-lxRCMpPr7up01Pp1FRjOe49ne6imWwi1b-ue8yQ&m=ffK7KOhRfCaxgCoIQ9h6qg_M4To0aL35iSCn1n5XJTE&s=JJbkUdgnekK0uj48svctaM5eJK6fp0RSwuiJOBs0Lg8&e=link:
As an Amazon Associate we earn from qualifying purchases.
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.