Logo

SQL Server ONES Function

Updated 2023-10-19 15:56:11.950000

Description

Use the scalar function ONES to generate an m-by-n matrix of ones.

Syntax

SELECT [westclintech].[wctMath].[wct].[ONES](
  <@m, int,>
 ,<@n, int,>)

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.

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.

RowNumColNumItemValue
001
011
021
031
041
101
111
121
131
141
201
211
221
231
241
301
311
321
331
341
401
411
421
431
441