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 > syntax error in sybase

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-20-11, 04:46
manhjk manhjk is offline
Registered User
 
Join Date: May 2011
Posts: 13
syntax error in sybase

Create Table #t (Cat nvarchar(2),Value int)
Insert into #t
Select 'A', 1 union all
Select 'B', 1 union all
Select 'A', 0 union all
Select 'C', 3 Union all
Select 'B', 2

Select T.Cat,T.Value,
Case When T.Cat=tt.Cat
Then tt.min2
Else T.min2
End
from Select *,0 As min2
From #t as T
Left outer join
(Select Cat, Min(Value) As Value, 1 As min2
From #t as tt
Group by Cat )
On T.CAt=tt.cat and T.value=tt.value

About code can't run in sybase, any idea?
Reply With Quote
  #2 (permalink)  
Old 05-20-11, 04:56
Martijnvs Martijnvs is offline
Registered User
 
Join Date: Jan 2004
Location: The Hague/Utrecht, NL
Posts: 415
What error do you get?
__________________
I'm not crazy, I'm an aeroplane!
Reply With Quote
  #3 (permalink)  
Old 05-20-11, 05:28
manhjk manhjk is offline
Registered User
 
Join Date: May 2011
Posts: 13
Hi Martijnvs,

I am using ase 12.5

I found that I can't use left outer join in this version.

any idea to change it not to use left outer join

thank.
Reply With Quote
  #4 (permalink)  
Old 05-20-11, 05:52
Martijnvs Martijnvs is offline
Registered User
 
Join Date: Jan 2004
Location: The Hague/Utrecht, NL
Posts: 415
What are you trying to accomplish? What is the select-statement supposed to return?
__________________
I'm not crazy, I'm an aeroplane!
Reply With Quote
  #5 (permalink)  
Old 05-22-11, 22:25
manhjk manhjk is offline
Registered User
 
Join Date: May 2011
Posts: 13
select min Value

Table #t
Cat ,Value
'A', 1
'B', 1
'A', 0
'C', 3
'B', 2

I want to select the min Value by Cat (the Cat data is not limit to A, B, C) and use 1 to indicate that it is min in the alias column Min_Value

expect output

Cat, Value, Min_Value
'A', 1, 0
'B', 1, 1
'A', 0, 1
'C', 3, 1
'B', 2, 0
Reply With Quote
  #6 (permalink)  
Old 05-22-11, 22:57
manhjk manhjk is offline
Registered User
 
Join Date: May 2011
Posts: 13
Create Table #t (Cat nvarchar(2),Value int)
Insert into #t
Select 'A', 1 union all
Select 'B', 1 union all
Select 'A', 0 union all
Select 'C', 3 Union all
Select 'B', 2


select *,
case
when (select min(#t.Value) from #t as #t2 where #t2.Cat = #t.Cat) = #t.Value)
then 0
else 1
end as min_Value
from #t


Can I use another select in the case when statement?
but i got the following error
Incorrect syntax near ')'.
Reply With Quote
  #7 (permalink)  
Old 05-23-11, 03:27
Martijnvs Martijnvs is offline
Registered User
 
Join Date: Jan 2004
Location: The Hague/Utrecht, NL
Posts: 415
You are missing a (. The are 2 ('s and 3 )'s.
__________________
I'm not crazy, I'm an aeroplane!
Reply With Quote
  #8 (permalink)  
Old 05-23-11, 04:15
manhjk manhjk is offline
Registered User
 
Join Date: May 2011
Posts: 13
Martijnvs, thank you
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