COUNT
Updated 2023-10-20 22:01:01.303000
Syntax
SELECT [westclintech].[wct].[COUNT] (
<@TableName, nvarchar(4000),>
,<@ColumnName, nvarchar(4000),>
,<@GroupedColumnName, nvarchar(4000),>
,<@GroupedColumnValue, sql_variant,>)
Description
Use the scalar function COUNT to count the number of rows in a resultant table that contain numbers using dynamic SQL.
Arguments
@GroupedColumnName
the name, as text, of the column in the table or view specified by @TableName which will be used for grouping the results.
@ColumnName
the name, as text, of the column in the table or view specified by @TableName that contains the to be used in the COUNT calculation.
@TableName
the name, as text, of the table or view that contains the values to be used in the COUNT calculation.
@GroupedColumnValue
the column value to do the grouping on.
Return Type
float
Remarks
COUNT returns that number of rows in the resultant table than can be evaluated as numbers. Nulls, text, and any value of a that cannot be implicitly converted to float are excluded.
No GROUP BY is required for this function even though it produces aggregated results.
Examples
CREATE TABLE #c1
(
[num] [varchar](10) NULL
);
insert into #c1
values
(1.5);
insert into #c1
values
(2.5);
insert into #c1
values
(2.75);
insert into #c1
values
(3.2);
insert into #c1
values
(5.675);
insert into #c1
values
('wct');
select wct.count('#c1', 'num', '', NULL);
This produces the following result
{"columns":[{"field":"column 1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"column 1":"5"}]}