Skip to Content
avatar image
Former Member

SQL Query in MAxDB..

Hi Friends,

Could you please let me know what should i change to execute the query in MaxDB?

select distinct t1.*, iif(t2.id is NULL, 0, 1) as hassub from content t1 left join content t2 on (t1.id=t2.parent_id) where t1.parent_id=" & id & " order by t1.parent_id,t1.sort

Thanks for ur help..

Rgds,

Pradeep

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Sep 14, 2008 at 12:00 PM

    Hi Pradeep,

    please make sure to consult the MaxDB documentation before [http://maxdb.sap.com/documentation].

    For what you want to archieve here (replacing NULL values with zeros), the [DECODE|http://maxdb.sap.com/doc/7_6/cf/63316bc03511d2a97100a0c9449261/content.htm] function should work.

    Concerning the

    where t1.parent_id=" & id & "
    

    please don't do that. For things like that BIND variables had been invented a long time ago.

    Just concatenating strings to form a statement is one of the major roads to SQL-injection and shared cursor cache failure.

    regards,

    Lars

    Add comment
    10|10000 characters needed characters exceeded

    • >

      > Yeah.. I will take care of it. Thanks.

      >

      > But how to make this statement working?!! Since SQL statement itself not working..i am really confused what to do next!

      Man... read my reply !.

      As I wrote, use 'DECODE' instead of 'IF'...

      select distinct t1.*, DECODE(t2.id, NULL, 0, 1) hassub 
      from 
           content t1 
          left join content t2 on (t1.id=t2.parent_id) 
      where 
         t1.parent_id=" + id + " 
      order by t1.parent_id, t1.sort
      

      Be aware that I've changed the NOT NULL test to a NULL test and therefore switched the positions of the wanted output values (from 1,0 to 0,1).

      To run the statement you will have to fill in some value for "+ id +" first, e.g.

         t1.parent_id= 10 
      

      If this does not help you - well, then you'll probably need more help than what I can provide via this forum...

      regards,

      Lars