IMSUM
Updated 2024-03-13 20:09:05.917000
Syntax
SELECT [westclintech].[wct].[IMSUM] (
<@IMValues_Tablename, nvarchar(4000),>
,<@ColumnName, nvarchar(4000),>
,<@GroupedColumnName, nvarchar(4000),>
,<@GroupedColumnValue, sql_variant,>)
Description
Use the scalar function IMSUM to return the sum of a dataset of complex numbers in x + yi or x + yj text format using dynamic SQL. The sum of 2 complex numbers is computed as:
(a+bi)+(c+di)=(a+c)+(b+d)i
Arguments
@GroupedColumnName
the name, as text, of the column in the table or view specified by @IMValues_Tablename which will be used for grouping the results.
@IMValues_Tablename
the name, as text, of the table or view that contains the complex numbers to be used in the IMSUM calculation.
@ColumnName
the name, as text, of the column in the table or view specified by @IMValues_Tablename that contains the complex numbers to be used in the IMSUM calculation.
@GroupedColumnValue
the column value to do the grouping on.
Return Type
nvarchar(4000)
Remarks
Use COMPLEX to convert real and imaginary coefficients into a complex number.
For more complex queries consider using the IMSUM_q function.
Examples
create table #s1
(
inumber varchar(50)
);
insert into #s1
values
('2+i');
insert into #s1
values
('2-i');
insert into #s1
values
('3+2i');
insert into #s1
values
('3-2i');
select wct.imsum('#s1', 'inumber', '', NULL);
This produces the following result.
{"columns":[{"field":"column 1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"column 1":"10"}]}
select wct.IMADD(wct.IMADD('2+i','2-i'), wct.IMADD('3+2i','3-2i'));
This produces the following result.
{"columns":[{"field":"column 1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"column 1":"10"}]}