sql - Why my prepared statement doesn't work, while regular statement work in DB2? -


i have strange behavior when try use following query preparedstatement

query following:

select      case           when type '%linux%' 'linux'          else 'unknown'     end os,  count(*) total   computers.os   group      case            when type '%linux%' 'linux'         else 'unknown'      end 

and works well. when create query following:

select      case           when type ? ?         else 'unknown'      end os,  count(*) total   computers.os   group      case            when type ? ?          else 'unknown'     end 

and set accordingly

string os = "linux"; ps.setstring(1, "%" +  os  + "%"); ps.setstring(2, os); ps.setstring(3, "%" +  os  + "%"); ps.setstring(4, os); 

it doesn't work , throw following error:

sqlcode=-119, sqlstate=42803, sqlerrmc=type column reference in select or having clause invalid, because not grouping column; or column reference in group clause invalid.

somebody can me explain please what's wrong preparedstatement?

thank you.

this might have parameters , how db2 determines if group by clause identical columns in select. simple work around use subquery:

select os, count(*) total  (select os.*,              (case when type '%linux%' 'linux'                     else 'unknown'               end) os       computers.os os      ) os group os; 

for wildcard version, put wildcards in once , compiler should accept query.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -