select count(category) from list where category like \'action\'
above is a query i want to run. However, when I run that query, I am getting data
count()
always return int
like type.
Read result data with int
accessor: eg. getInt(1)
You cant apply COUNT() function on text,ntext,image datatypes.
Why you can't use :
select count(*) from list where category like 'action'
? Do you have some nulls ?
If you don't have to exclude null value the above query could already work well ...
To answer the question in the title for future googlers you can use
SELECT COUNT(CASE
WHEN some_text_column IS NOT NULL THEN 1
END)
FROM some_table
In your case though (as pointed out in the comments by @hvd) the WHERE category LIKE 'action'
predicate ensures that any NULL
values will be excluded anyway so it is safe to replace it with COUNT(*)
Moreover you almost certainly should not be using the text
datatype for this. This is a deprecated datatype that was intended for holding LOB (Large Object) data over 8000 bytes.
Strings like "action" definitely do not fit this description!