SQL Fiddle is currently down regarding MS SQL Server code, so here is a dropbox link to a .txt containing the DDL to create the schema I'm using:
I'm studying for an exam and struggling with an example problem.
Create a function to calculate the total cost of a software package (given the software package’s name) installed in each department in the last three years. Check whether the name is accurate.
Here's my solution:
create function total_cost_of_sofpack_in_lst3yrs(@pack_name varchar(20))
select sum(packcost)as total_pk_cost, location
inner join software on package.PACK=software.PACK
inner join pc on software.tagnum=pc.tagnum
and software.INSTDATE > dateadd(year, -3, getdate())
group by pc.location
select dbo.total_cost_of_sofpack_in_lst3yrs('Manta') as R
Since the return type is
TABLE from the function, you need to call as
SELECT * FROM dbo.total_cost_of_sofpack_in_lst3yrs('Manta')