postgresql , how can i add to my query a list of values to the where clause ?

hello experts,

i'm looking on how to add a list of values at the end of my query in order to
receive the answer only for a group of values.

i'm looking to add somegthing like the last line,
except that my values are not comming from a subquery.

 
  WHERE
  CD.rf_card_id = TB.rf_card_id
  AND
  CD.account_id = AC.account_id
  AND
  TB.container_id = TB.container_id
  AND account_id in (101, 102, 103, 104, 110)    <-


thank you in advance.
toshi_Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
earth man2Connect With a Mentor Commented:
somewhere  you need to build the account_id string as a comma seperated list then append it to the string buffer for your query.

sinply ...
  String acids = "101, 102, 103, 104, 110";

 sb.Append( " AND AC.account_id in ("  );
 sb.Append( acids );
  sb.Append( " )" );

  sb.Append(" ORDER BY TB.date ASC; ");
0
 
gheistCommented:
Edit the statement
If this is prepared statement - pass array of strings as parameter in place.
0
 
toshi_Author Commented:
hello gheist,
could you be more explicit please,

i'm not an expert, neither with postgresql nor with english ;o)

what i would need is to view how to write the list,
i'll correcte the string generation after what is correct.


thank you for further help.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
gheistCommented:
It is not PostgreSQL problem.

How do you pass statement to PostgreSQL?
Where does it come from?
0
 
toshi_Author Commented:
i pass my query from .NET c# to
postgresql 8.4 through Npgsql,


..................
     //sb.Append(" TB.weight*0.5 as GEWICHT, ") ;
            sb.Append(" CASE WHEN  ") ;
                sb.Append(" TB.weight*0.5 >= 0.5 AND ") ;
                sb.Append(" TB.weight*0.5 <= 5.0 ") ;
                    sb.Append(" THEN 5.0 ") ;
                sb.Append(" ELSE TB.weight*0.5 ") ;
            sb.Append(" END AS GEWICHT, ") ;

            sb.Append(" 0 as FNFLAG,");
            sb.Append(" CD.rf_card_id  as RFCID, ");    
            sb.Append(" AC.account_id as ACCID ");
            sb.Append(" FROM ");
            sb.Append(" trash_bag as TB, rf_card as CD, account as AC ");
            sb.Append(" WHERE ");
            sb.Append(" CD.rf_card_id = TB.rf_card_id ");
            sb.Append(" AND ");
            sb.Append(" CD.account_id = AC.account_id ");
            sb.Append(" AND ");
            sb.Append(" TB.container_id = TB.container_id ");


// i want to reduce the query by passing a list of containers.


            // TIME
            // sb.Append(" AND TB.date > '2008-01-01' ");
            //sb.Append(" AND TB.date > '" + aBegin.ToString(PgsSymbolicConstant.DATE_FORMAT_DB)+  "'");
            sb.Append(" AND TB.date > '" + aBegin.ToString(PgsSymbolicConstant.DATETIME_FORMAT_DB)+  "'");
            // sb.Append(" AND TB.date < '2008-01-31' ");
            //sb.Append(" AND TB.date <= '" + _theEnd.ToString(PgsSymbolicConstant.DATE_FORMAT_DB)+  "'");
            sb.Append(" AND TB.date <= '" + _theEnd.ToString(PgsSymbolicConstant.DATETIME_FORMAT_DB)+  "'");
            sb.Append(" ORDER BY date ASC; ");

            DataTable _dtForExport = dba_.ExecuteQuery(sb.ToString());

            //DataTable _dtFiltered= FilterZerosAndMinimal(_dtForExport);

            return _dtForExport;
0
 
gheistCommented:
I have asked moderators to add .net area(s), there is nothing specific to PostgreSQL in your .NET program
0
 
toshi_Author Commented:
??????
i'd like to know how to set a list of values to restrict my query,
is a question of query,
it doesnt nothing have to do with .NET
i think i 'm not accurate enough with english language

but there's someting I'M SURE "this is a postresql question"


0
All Courses

From novice to tech pro — start learning today.