Joined: 17 Mar 2014
Online Status: Offline
Posts: 53
Topic: having trouble with a sql SP statement Posted: 28 Mar 2014 at 4:31am
I have 3 records grouped by ticket number(it is a field in my table), in 2 of them I have the same stdesc but in the other one I have a description that contains FREIGHT' word. If sttot field >0 and stdesc contains FREIGHT' word, I would like to get the other description else just stdesc
I am trying to add this
stdesc=max(case when(sttot >0 and stdesc like '%FREIGHT') then (stdesc = stdesc is not like '%FREIGHT') else stdesc end),
to a sql statement and sql gave me the following message
Joined: 13 Jun 2011
Online Status: Offline
Posts: 475
Posted: 28 Mar 2014 at 2:37pm
this might work
select ticket#, max(case when x.stdesc is null then y.stdesc else x.stdesc end) as x.stdesc
from some_table as y left outer join( select ticket#, max(stdesc) as stdesc from some_table where (sttot >0 and stdesc like '%FREIGHT') group by ticket# ) as x on x.ticket# = y.ticket# group by ticket#
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum