--
-- USER DEFINED TYPES and USER DEFINED AGGREGATES
-- Complete the DDL and DML statements below
use pubs
go

-- You MUST manually drop objects that use UDT
-- before dropping and recreating UDT
drop table complex_tab
go

drop function add_complex
go

/* uncomment this if you want to use manual deployment
drop aggregate ComplexSum
go

drop type ComplexNumber
go

drop assembly ComplexNumber
go

-- create assembly for ComplexNumber
create assembly 


-- CREATE ComplexNumber type
--
create type 
go

*/

--
-- CREATE TABLE WITH UDT COLUMNS
--
create table complex_tab(
go

-- insert rows

-- this returns an error
-- select * from complex_tab
-- go

-- select values
select 
go

-- create function in T-SQL
create function add_complex(@x ComplexNumber, @y ComplexNumber)
returns ComplexNumber
as
begin

end
go

-- test it
declare @x as ComplexNumber
declare @y as ComplexNumber
declare @z as ComplexNumber

set @z = dbo.add_complex(@x, @y)
print @z.realpart
print @z.imagpart

-- create aggregate
-- code the DDL statement if you want to use manual deployment

-- use udagg
select convert(varchar, dbo.ComplexSum(cnumber)) from complex_tab
go