function ChangeText(obj, demo){
    var demoQuery = demo;
    if(demo == 'h1')
    {
      demoQuery = 
        "select *\n"
      + "  from millimil..MPAHalo\n"
      + " where snapnum=50 \n"
      + "   and np between 100 and 1000 \n"
      + "   and x between 10 and 20\n"
      + "   and y between 10 and 20\n"
      + "   and z between 10 and 20\n";
    }
    if(demo == 'g1')
    {
      demoQuery = 
        "select *\n"
      + "  from millimil..DeLucia2006a\n"
      + " where snapnum=63\n"
      + "   and mag_b between -26 and -18 \n"
      + "   and x between 10 and 20\n"
      + "   and y between 10 and 20\n"
      + "   and z between 10 and 20\n";
    }
    if(demo == 'h2')
    {
         demoQuery = 
           "select PROG.*\n"
         + "  from millimil..MPAHalo PROG,\n"
         + "       millimil..MPAHalo DES\n"
         + " where DES.haloId = 1\n"
         + "   and PROG.haloId between DES.haloId and DES.lastprogenitorId\n"

    }
    if(demo == 'g2')
    {
         demoQuery = 
           "select PROG.*\n"
         + "  from millimil..DeLucia2006a PROG,\n"
         + "       millimil..DeLucia2006a DES\n"
         + " where DES.galaxyId = 1\n"
         + "   and PROG.galaxyId between DES.galaxyId and DES.lastprogenitorId\n"

    }
    if(demo == 'h3')
    {
         demoQuery = 
           "select DES.haloId as descendant_id,\n"
         + "       DES.np as descendant_mass,\n"
         + "       PROG.*\n"
         + "  from millimil..MPAHalo DES,\n"
         + "       millimil..MPAHalo PROG\n"
         + " where DES.snapnum = 63\n"
         + "   and DES.np > 4000\n"
         + "   and PROG.haloId between DES.haloId and DES.lastprogenitorId\n"
         + "   and PROG.snapnum = 30\n"
         + "   and PROG.np > 100\n"
         + " order by DES.np desc, PROG.np desc\n";
    }
    if(demo == 'g3')
    {
         demoQuery = 
           "select DES.galaxyId as descendant_id,\n"
         + "       DES.stellarMass as descendant_mass,\n"
         + "       PROG.*\n"
         + "  from millimil..DeLucia2006a DES,\n"
         + "       millimil..DeLucia2006a PROG\n"
         + " where DES.snapnum = 63\n"
         + "   and DES.mag_b < -20\n"
         + "   and PROG.galaxyId between DES.galaxyId and DES.lastprogenitorId\n"
         + "   and PROG.snapnum = 30\n"
         + "   and PROG.mag_b < -19\n"
         + " order by DES.mag_b asc, PROG.mag_b asc\n";
    }
    if(demo == 'h4')
    {
         demoQuery = 
           "select D.haloId,\n"
         + "       D.snapnum,\n"
         + "       D.np as d_np,\n"
         + "       P1.np as p1_np,\n"
         + "       P2.np as p2_np\n"
         + "  from millimil..MPAHalo P1,\n"
         + "       millimil..MPAHalo P2,\n"
         + "       millimil..MPAHalo D\n"
         + " where P1.SNAPNUM=P2.SNAPNUM\n"
         + "   and P1.haloId < P2.haloId\n"
         + "   and P1.descendantId = D.haloId\n"
         + "   and P2.descendantId = D.haloId\n"
         + "   and P1.np >= .2*D.np\n"
         + "   and P2.np >= .2*D.np\n"
         + "   and D.np > 1000";
    }
    if(demo == 'g4')
    {
         demoQuery = 
           "select D.galaxyId,\n"
         + "       D.snapnum,\n"
         + "       D.mag_b as d_mag_b,\n"
         + "       D.sfr as d_sfr,\n"
         + "       P1.mag_b as p1_mag_b,\n"
         + "       P2.mag_b as p2_mag_b,\n"
         + "       D.stellarMass as d_mass,\n"
         + "       P1.stellarMass as p1_mass,\n"
         + "       P2.stellarMass as p2_mass\n"
         + "  from millimil..DeLucia2006a P1,\n"
         + "       millimil..DeLucia2006a P2,\n"
         + "       millimil..DeLucia2006a D\n"
         + " where P1.SNAPNUM=P2.SNAPNUM\n"
         + "   and P1.galaxyId< P2.galaxyId\n"
         + "   and P1.descendantId = D.galaxyId\n"
         + "   and P2.descendantId = D.galaxyId\n"
         + "   and P1.stellarMass >= .2*D.stellarMass\n"
         + "   and P2.stellarMass >= .2*D.stellarMass\n"
         + "   and D.mag_b <-20";
    }
     if(demo == 'h5')
    {
      demoQuery =
       " select power(10, .1*(.5+floor(log10(np)/.1))) as mass,\n"
      +"        count(*) as num\n"
      +"   from millimil..MPAHalo\n"
      +"  where snapnum=63\n"
      +" group by power(10, .1*(.5+floor(log10(np)/.1)))\n"
      +" order by mass    ";
    }
    if(demo == 'g5')
    {
      demoQuery = 
     "select .2*(.5+floor(mag_b/.2)) as mag,\n"
    +"       count(*) as num\n"
    +"  from millimil..DeLucia2006a\n"
    +" where mag_b < -10\n"
    +"   and snapnum=63\n"
    +" group by .2*(.5+floor(mag_b/.2))\n"
    +" order by mag    ";
    }
    if(demo == 'g6')
    {
         demoQuery = 
           "select vVir, mag_b, mag_v, mag_i, mag_r, mag_k\n"
         + "  from millimil..DeLucia2006a\n"
         + " where (bulgeMass < 0.1*stellarMass or bulgeMass is null)\n"
         + "   and snapnum = 41 \n";
    }
     if(demo == 'hg2')
    {
      demoQuery =
      "select power(10, .1*(.5+floor(log(g.np)/.1))) as halo_np,\n"
     +"       avg(g.stellarMass) as stars_avg,\n"
     +"       max(g.stellarMass) as stars_max,\n"
     +"       avg(g.bulgeMass) as bulge_avg,\n"
     +"       max(g.bulgeMass) as bulge_max,\n"
     +"       avg(g.mag_b-g.mag_v) as color_avg\n"
     +"  from millimil..DeLucia2006a g\n"
     +" where g.snapnum= 63 \n"
     +"   and g.mag_b < 0\n"
     +" group by np\n"
     +" order by np\n";    
          }
    
     if(demo == 'hg1')
    {
      demoQuery =
      "select 0*galaxyId as lim, \n"
     +"       .2*(.5+floor(mag_b/.2)) as mag,\n"
     +"       count(*) as num\n"
     +"  from millimil..DeLucia2006a g, \n"
     +"       millimil..MPAHalo h\n"
     +" where h.np between 2000 and 3000\n"
     +"   and h.snapnum=63\n"
     +"   and g.haloId = h.haloId\n"
     +"   and g.mag_b < 0\n"
     +" group by 0*galaxyId, .2*(.5+floor(mag_b/.2))\n"
     +"union\n"
     +"select 0*galaxyId+1 as lim, \n"
     +"       .2*(.5+floor(mag_b/.2)) as mag,\n"
     +"       count(*) as num\n"
     +"  from millimil..DeLucia2006a g, \n"
     +"       millimil..MPAHalo h\n"
     +" where h.np between 200 and 300\n"
     +"   and h.snapnum= 63\n"
     +"   and g.haloId = h.haloId\n"
     +"   and g.mag_b < 0\n"
     +" group by 0*galaxyId+1, .2*(.5+floor(mag_b/.2))\n"
     +"order by lim,  mag  \n";  
    }
     if(demo == 'hf1')
    {
      demoQuery =
       "select h.*\n"
      +"  from millimil..MPAHalo h,\n"
      +"       millimil..MMField f\n"
      +" where f.g5 between 2 and 3\n"
      +"   and f.snapnum=63\n"
      +"   and f.snapnum = h.snapnum\n"
      +"   and f.phkey = h.phkey";
    }
    
     if(demo == 'hf2')
    {
      demoQuery =
      "select 0*haloId as lim, \n"
     +"       power(10, .1*(.5+floor(log10(h.np)/.1))) as mass,\n"
     +"       count(*) as num\n"
     +"  from millimil..MPAHalo h, \n"
     +"       millimil..MMField f\n"
     +" where f.g5 between 3 and 5\n"
     +"   and f.snapnum=63\n"
     +"   and f.snapnum = h.snapnum\n"
     +"   and f.phkey = h.phkey    \n"
     +" group by 0*haloId, power(10, .1*(.5+floor(log10(h.np)/.1)))\n"
     +"union\n"
     +" select 0*haloId+1 as lim,\n" 
     +"        power(10, .1*(.5+floor(log10(h.np)/.1))) as mass,\n"
     +"        count(*) as num\n"
     +"  from millimil..MPAHalo h, \n"
     +"       millimil..MMField f\n"
     +" where f.g5 between .2 and .4\n"
     +"   and f.snapnum=63\n"
     +"   and f.snapnum = h.snapnum\n"
     +"   and f.phkey = h.phkey    \n"
     +" group by 0*haloId+1, power(10, .1*(.5+floor(log10(h.np)/.1)))\n"
     +"order by lim,mass    \n";  
    }
     if(demo == 'gf2')
    {
      demoQuery =
      "select 0*galaxyId as lim, \n"
     +"       .2*(.5+floor(mag_b/.2)) as mag,\n"
     +"       count(*) as num\n"
     +"  from millimil..DeLucia2006a g, \n"
     +"       millimil..MMField f\n"
     +" where f.g5 between 3 and 5\n"
     +"   and f.snapnum=63\n"
     +"   and f.snapnum = g.snapnum\n"
     +"   and f.phkey = g.phkey    \n"
     +"   and g.mag_b < 0 \n"
     +" group by 0*galaxyId, .2*(.5+floor(mag_b/.2))\n"
     +"union\n"
     +" select 0*galaxyId+1 as lim,\n" 
     +"        .2*(.5+floor(mag_b/.2)) as mag,\n"
     +"        count(*) as num\n"
     +"  from millimil..DeLucia2006a g, \n"
     +"       millimil..MMField f\n"
     +" where f.g5 between .2 and .4\n"
     +"   and f.snapnum=63\n"
     +"   and f.snapnum = g.snapnum\n"
     +"   and f.phkey = g.phkey    \n"
     +"   and g.mag_b < 0 \n"
     +" group by 0*galaxyId+1, .2*(.5+floor(mag_b/.2))\n"
     +"order by lim,  mag  \n";  
    }
    
    if(demo == 'hf3')
   {
     demoQuery =
      "select zmax, avg(g5) as g5, stdev(g5) as g5err,\n"
     +"       avg(g10) as g10, stdev(g10) as g10err,\n"
     +"       count(*) as num\n"
     +"  from millimil..mmfield f, \n"
     +"       ( select des.haloId, des.np, des.phkey,max(PROG.redshift) as zmax\n"
     +"           from millimil..MPAHalo PROG,\n"
     +"                millimil..MPAHalo DES\n"
     +"          where DES.snapnum = 63\n"
     +"            and PROG.haloId between DES.haloId and DES.lastprogenitorId\n"
     +"            and prog.np >= des.np/2    \n"
     +"            and des.np between 100 and 200\n"
     +"            and des.haloId = des.firsthaloinfofgroupid\n"
     +"          group by des.haloId, des.np ,des.phkey    \n"
     +"       ) t\n"
     +" where t.phkey = f.phkey \n"
     +"   and f.snapnum=63\n"    
     +"group by zmax \n";
         
   }
    
    obj.SQL.value=demoQuery;
    return true; 
}

