November 8, 2007 at 12:40 am
i have some problems to converting the following sql statement to ansi conform join operators.
select ma_idx, ma_kurztext_deu, kd.kd_preis, kl.kd_preis
from debitor, material, kondition kd, kondition kl
where db_idx = 9009000 and db_ko_vkpreis = kd.kd_pl_idx and
db_vkorg = kd.kd_vkorg and kd.kd_name = 'PR00' and
ma_idx = kd.kd_ma_idx and GetDate() between
kd.kd_gueltig_von and kd.kd_gueltig_bis and
db_ko_ldpreis *= kl.kd_pl_idx and
db_vkorg *= kl.kd_vkorg and ma_idx *= kl.kd_ma_idx and
kl.kd_name = 'ZPL1' and GetDate() between
kl.kd_gueltig_von and kl.kd_gueltig_bis
November 8, 2007 at 12:51 am
Do you know what *= means?
--Jeff Moden
Change is inevitable... Change for the better is not.
November 8, 2007 at 12:55 am
Yes, i know. In a compatibility level SQL 2000 the statement works correctly. I need this statement for compatibility level SQL 2005.
November 8, 2007 at 1:20 am
Before we can suggest anything at all, you need to prefix ALL columns with proper table name or table alias.
N 56°04'39.16"
E 12°55'05.25"
November 8, 2007 at 2:13 am
Here is the statement with full qualified name:
select ma.ma_idx, ma.ma_kurztext_deu, kd.kd_preis, kl.kd_preis
from debitor db, material ma, kondition kd, kondition kl
where db.db_idx = 9009000 and db.db_ko_vkpreis = kd.kd_pl_idx and
db.db_vkorg = kd.kd_vkorg and kd.kd_name = 'PR00' and
ma.ma_idx = kd.kd_ma_idx and GetDate() between
kd.kd_gueltig_von and kd.kd_gueltig_bis and
db_ko_ldpreis *= kl.kd_pl_idx and
db.db_vkorg *= kl.kd_vkorg and ma.ma_idx *= kl.kd_ma_idx and
kl.kd_name = 'ZPL1' and GetDate() between
kl.kd_gueltig_von and kl.kd_gueltig_bis
Thanks
November 8, 2007 at 2:21 am
Try thisselectma.ma_idx,
ma.ma_kurztext_deu,
kd.kd_preis,
kl.kd_preis
fromdebitor as db
inner joinkondition as kd on kd.kd_pl_idx = db.db_ko_vkpreis
and kd.kd_vkorg = db.db_vkorg
inner joinmaterial as ma on ma.ma_idx = kd.kd_ma_idx
left joinkondition as kl on kl.kd_pl_idx = {table alias here}.db_ko_ldpreis
and kl.kd_vkorg = db.db_vkorg
and kl.kd_ma_idx = ma.ma_idx
and kl.kd_name = 'ZPL1'
and GetDate() between kl.kd_gueltig_von and kl.kd_gueltig_bis
wheredb.db_idx = 9009000
and kd.kd_name = 'PR00'
and GetDate() between kd.kd_gueltig_von and kd.kd_gueltig_bis
N 56°04'39.16"
E 12°55'05.25"
November 8, 2007 at 4:39 am
As the kl filters are after the join in the where clause, I suspect the following:
SELECT ma_idx, ma_kurztext_deu, kd.kd_preis, kl.kd_preis
FROM debitor D
    JOIN kondition kd
        ON D.db_ko_vkpreis = kd.kd_pl_idx
            AND D.db_vkorg = kd.kd_vkorg
    JOIN material M
        ON kd.kd_ma_idx = M.ma_idx
    JOIN kondition kl
        ON D.db_ko_ldpreis = kl.kd_pl_idx
            AND D.db_vkorg = kl.kd_vkorg
            AND M.ma_idx = kl.kd_ma_idx
WHERE D.db_idx = 9009000
    AND kd.kd_name = 'PR00'
    AND GETDATE() BETWEEN kd.kd_gueltig_von AND kd.kd_gueltig_bis
    AND kl.kd_name = 'ZPL1'
AND GETDATE() BETWEEN kl.kd_gueltig_von AND kl.kd_gueltig_bis
November 13, 2007 at 6:50 am
BrekerS (11/8/2007)
i have some problems to converting the following sql statement to ansi conform join operators.select ma_idx, ma_kurztext_deu, kd.kd_preis, kl.kd_preis
from debitor, material, kondition kd, kondition kl
where db_idx = 9009000 and db_ko_vkpreis = kd.kd_pl_idx and
db_vkorg = kd.kd_vkorg and kd.kd_name = 'PR00' and
ma_idx = kd.kd_ma_idx and GetDate() between
kd.kd_gueltig_von and kd.kd_gueltig_bis and
db_ko_ldpreis *= kl.kd_pl_idx and
db_vkorg *= kl.kd_vkorg and ma_idx *= kl.kd_ma_idx and
kl.kd_name = 'ZPL1' and GetDate() between
kl.kd_gueltig_von and kl.kd_gueltig_bis
The easiest way to do that is simply create a new view, but don't add any tables. Paste your code into the sql window and then execute your query. SQL Server will automatically convert your code to the ANSI version. This works in both 2000 and 2005.
Viewing 8 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply