SQL IIF group by result in MS Access 2007 -


i using sql have thought should work. fast learning ms access has it's own idea of how use sql.

select count([system_info].[id]) countofid, iif(left([system_info].[csmemory],len([system_info].[csmemory])-3)  < 512000, "<512mb",  iif(left([system_info].[csmemory],len([system_info].[csmemory])-3)  < 1000000, "512mb - 1gb", "nope")) memorytext system_info group memorytext; 

so above code gives me error message "you tried execute query not include specified expression xxx part of aggregate function".

i've googled fair bit , still pretty stuck. if remove count , groupby, query run , see list of labels create "memorytext".

thanks help.

if remove count , groupby, query run , see list of labels create "memorytext".

in case, save version works qrybase:

select [system_info].[id]), iif(left([system_info].[csmemory],len([system_info].[csmemory])-3)  < 512000, "<512mb",  iif(left([system_info].[csmemory],len([system_info].[csmemory])-3)  < 1000000, "512mb - 1gb", "nope")) memorytext system_info; 

then aggregate query can be:

select memorytext, count(id) countofid qrybase group memorytext; 

edit: however, expression puzzles me:

left([system_info].[csmemory],len([system_info].[csmemory])-3)  < 512000 

instead of 512000, have expected 524288 (512 * 1024).

and output left() string, expression compares string number. although database engine may cast string number before comparison, explicitly.

val(left([system_info].[csmemory],len([system_info].[csmemory])-3)) < 524288 

you may better suggestions if tell data type of csmemory field , show sample values.

edit2: access' help: the val function stops reading string @ first character can't recognize part of number.

so val("2052644 kb") ignore non-digit characters , give number 2052644. however, sample values include commas, val() stop reading @ first comma ... val("2,052,644 kb") give 2.

if query run within access session access 2000 or newer, use replace() function strip out commas (replace commas zero-length strings) before evaluating text val(). in immediate window:

? replace("2,052,644 kb", ",", "") 2052644 kb  ? val(replace("2,052,644 kb", ",", ""))  2052644  

so instead of using left() , len(), use:

val(replace(csmemory, ",", ""))  < 512000 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -