Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL script

Status
Not open for further replies.

Stevennn

Programmer
Apr 4, 2007
52
US
I'm trying to execute the script below and it wont do it.
Is it possible to figure out what is wrong with it!
"SQL command not properly ended"
Thank-you

SELECT
en_code,
sa_sub,
costctr_code,
acc_code,
sum(gl_amt)
FROM
D_ENTITY_STG1 a,
D_SUBACCTS_STG1 b,
D_COSTCTR_STG1 c,
D_ACCTS_STG1 d,
F_ACCT_TRX_HIST_STG1 e
WHERE
a.en_code = c.gl_ent,
b.sa_sub = e.gl_sa,
c.costctr_code = e.gl_ctr,
d.acc_code = e.gl_acc
GROUP BY
a.en_code, b.sa_sub, c.costctr_code, d.acc_cod
 
That's an Oracle error message, and this is a Microsoft SQL Server forum. I suggest that you re-post this question in the oracle forum.

Alternatively...

[google]SQL command not properly ended[/google]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
in your where clause, you should have AND instead of commas between conditions, like this:

Code:
[COLOR=blue]SELECT[/color]
       en_code,
       sa_sub,
       costctr_code,
        acc_code,
        sum(gl_amt)
[COLOR=blue]FROM[/color]  
       D_ENTITY_STG1 a,
        D_SUBACCTS_STG1 b,
         D_COSTCTR_STG1 c,
       D_ACCTS_STG1 [COLOR=blue]d[/color],
       F_ACCT_TRX_HIST_STG1 e
[COLOR=blue]WHERE[/color]
       a.en_code = c.gl_ent AND
       b.sa_sub = e.gl_sa AND
       c.costctr_code = e.gl_ctr AND
       [COLOR=blue]d[/color].acc_code = e.gl_acc
[COLOR=blue]GROUP[/color] [COLOR=blue]BY[/color]
       a.en_code, b.sa_sub, c.costctr_code, [COLOR=blue]d[/color].acc_cod

That being said, one of my pet peeves is joins written in the fashion that yours are in this query. Here is an example of how to do it differently (I think this is easier to read, let me know what you think):

Code:
[COLOR=blue]SELECT[/color] a.en_code, b.sa_sub, c.costctr_code, [COLOR=blue]d[/color].acc_cod
, sum(g1_amt)
[COLOR=blue]from[/color]
D_ENTITY_STG1 a
[COLOR=blue]inner[/color] [COLOR=blue]join[/color]
D_SUBACCTS_STG1 b
[COLOR=blue]on[/color] a.en_code = c.gl_ent
[COLOR=blue]inner[/color] [COLOR=blue]join[/color]
D_COSTCTR_STG1 c
[COLOR=blue]on[/color] b.sa_sub = e.gl_sa
[COLOR=blue]inner[/color] [COLOR=blue]join[/color]
D_ACCTS_STG1 [COLOR=blue]d[/color]
[COLOR=blue]on[/color] c.costctr_code = e.gl_ctr
[COLOR=blue]inner[/color] [COLOR=blue]join[/color]
F_ACCT_TRX_HIST_STG1 e
[COLOR=blue]on[/color] [COLOR=blue]d[/color].acc_code = e.gl_acc
[COLOR=blue]GROUP[/color] [COLOR=blue]BY[/color] a.en_code, b.sa_sub, c.costctr_code, [COLOR=blue]d[/color].acc_cod

One advantage to using this syntax is you can be reasonably confident that it will work in future releases of SQL Server.

HOpe this helps,

Alex

Ignorance of certain subjects is a great part of wisdom
 
ha!

>>>One advantage to using this syntax is you can be reasonably confident that it will work in future releases of SQL Server.

If you are not using SQL Server, I suppose you don't really care about this huh?

Ignorance of certain subjects is a great part of wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top