Link to home
Start Free TrialLog in
Avatar of Erwin Pombett
Erwin PombettFlag for Switzerland

asked on

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.
Avatar of gheist
gheist
Flag of Belgium image

Edit the statement
If this is prepared statement - pass array of strings as parameter in place.
Avatar of Erwin Pombett

ASKER

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.
It is not PostgreSQL problem.

How do you pass statement to PostgreSQL?
Where does it come from?
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;
I have asked moderators to add .net area(s), there is nothing specific to PostgreSQL in your .NET program
??????
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"


ASKER CERTIFIED SOLUTION
Avatar of earth man2
earth man2
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial