ONES
Updated 2023-10-19 15:56:11.950000
Syntax
SELECT [westclintech].[wctMath].[wct].[ONES](
<@m, int,>
,<@n, int,>)
Description
Use the scalar function ONES to generate an m-by-n matrix of ones.
Arguments
@m
The number of rows in the ones matrix.
@n
The number of columns in the ones matrix.
Return Type
nvarchar(max)
Remarks
@m must be greater than or equal to 1.
@n must be greater than or equal to 1.
Examples
The following statement will produce the 5-by-5 ones matrix.
SELECT wct.ONES(5, 5) as ONES;
This produces the following result.
{"columns":[{"field":"ONES"}],"rows":[{"ONES":"1,1,1,1,1;1,1,1,1,1;1,1,1,1,1;1,1,1,1,1;1,1,1,1,1"}]}
We can use the table-valued function MATRIX to produce the output in third-normal form.
SELECT *
FROM wct.MATRIX(wct.ONES(5, 5));
This produces the following result.
{"columns":[{"field":"RowNum","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"ColNum","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"ItemValue","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"RowNum":"0","ColNum":"0","ItemValue":"1"},{"RowNum":"0","ColNum":"1","ItemValue":"1"},{"RowNum":"0","ColNum":"2","ItemValue":"1"},{"RowNum":"0","ColNum":"3","ItemValue":"1"},{"RowNum":"0","ColNum":"4","ItemValue":"1"},{"RowNum":"1","ColNum":"0","ItemValue":"1"},{"RowNum":"1","ColNum":"1","ItemValue":"1"},{"RowNum":"1","ColNum":"2","ItemValue":"1"},{"RowNum":"1","ColNum":"3","ItemValue":"1"},{"RowNum":"1","ColNum":"4","ItemValue":"1"},{"RowNum":"2","ColNum":"0","ItemValue":"1"},{"RowNum":"2","ColNum":"1","ItemValue":"1"},{"RowNum":"2","ColNum":"2","ItemValue":"1"},{"RowNum":"2","ColNum":"3","ItemValue":"1"},{"RowNum":"2","ColNum":"4","ItemValue":"1"},{"RowNum":"3","ColNum":"0","ItemValue":"1"},{"RowNum":"3","ColNum":"1","ItemValue":"1"},{"RowNum":"3","ColNum":"2","ItemValue":"1"},{"RowNum":"3","ColNum":"3","ItemValue":"1"},{"RowNum":"3","ColNum":"4","ItemValue":"1"},{"RowNum":"4","ColNum":"0","ItemValue":"1"},{"RowNum":"4","ColNum":"1","ItemValue":"1"},{"RowNum":"4","ColNum":"2","ItemValue":"1"},{"RowNum":"4","ColNum":"3","ItemValue":"1"},{"RowNum":"4","ColNum":"4","ItemValue":"1"}]}