If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Sybase > Incorrect syntax - ASE 12.5

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-14-11, 21:54
manhjk manhjk is offline
Registered User
 
Join Date: May 2011
Posts: 13
Incorrect syntax - ASE 12.5

I am using Sybase ASE 12.5 I have two table as follow

TableA
PID, Amount1
1, 10
1, 20
2, 10
2, 10
3, 30

TableB
PID, Amount2
1, 20
1, 50
2, 30
2, 20

SELECT one.pid
, one.Amount1OfSum
, two.Amount2OfSum
FROM ( SELECT pid
, SUM(Amount1) AS Amount1OfSum
FROM TableA
GROUP
BY pid ) AS one,
( SELECT pid
, SUM(Amount2) AS Amount2OfSum
FROM TableB
GROUP
BY pid ) AS two
where two.pid *= one.pid

What I want the output is
PID, Amount1, Amount2
1, 30, 70
2, 20, 50
3, 30,

Incorrect syntax near the keyword 'select'.
Incorrect syntax near ')'.
Reply With Quote
  #2 (permalink)  
Old 06-15-11, 02:48
aflorin27 aflorin27 is offline
Registered User
 
Join Date: Apr 2008
Location: Iasi, Romania
Posts: 317
I've run your statement on a 12.5.4 ASE without any errors.
__________________
Florin Aparaschivei
Iasi, Romania
Reply With Quote
  #3 (permalink)  
Old 06-15-11, 03:44
manhjk manhjk is offline
Registered User
 
Join Date: May 2011
Posts: 13
hi aflorin27,

Thank very much for your reply.

I still get incorrect syntax error.
I think ASE 12.5 version don't support this syntax,
just like the left join have to use *= instead of "left join"

I can't find the solution, do you know any other way to do the same query?

thank.
Reply With Quote
  #4 (permalink)  
Old 06-15-11, 10:03
aflorin27 aflorin27 is offline
Registered User
 
Join Date: Apr 2008
Location: Iasi, Romania
Posts: 317
select a.pid, sum(a.Amount1), sum(a.Amount2)
from
(
select pid, Amount1, 0 as Amount2
from TableA
union all
select pid, 0 as Amount1, Amount2
from TableB
) a
group by a.pid;
__________________
Florin Aparaschivei
Iasi, Romania
Reply With Quote
  #5 (permalink)  
Old 06-15-11, 21:55
manhjk manhjk is offline
Registered User
 
Join Date: May 2011
Posts: 13
Hi aflorin27,

Thank very much for your reply.

I finally got the answer.
Sybase ASE 12.5.0.3 version is not support "derivedtable", so it is not the syntex problem.

I have to do it by using temp table or sp

Thank
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On