July 3, 2013 at 2:05 am
a SQL statement that will perform a daily sum aggregation on the field cost. It must only use costs that are associated with the follow items: Z001, Z002. The cost must also only come from division 1. Below is the example table that you will be retrieving data from:
Costs
•Receipt
•Date
•Item
•Reason
•Division
•Cost
I have tried this :
use STEVENTEST
go
CREATE FUNCTION Daily_Cost1
(
@item varchar , @Division nchar
)
RETURNS money
AS
BEGIN
DECLARE @daily_cost money
DECLARE @Cost_date date
set @Cost_date = GETDATE ()
if
@item = 'Z001' OR @item ='Z002'
SELECT @daily_cost = SUM(cost) from Cost
where @Cost_date =@Cost_date
RETURN @daily_cost
END
GO
July 3, 2013 at 3:23 am
Is this homework or a real life problem?
-------------------------------Posting Data Etiquette - Jeff Moden [/url]Smart way to ask a question
There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan
I would never join a club that would allow me as a member - Groucho Marx
July 3, 2013 at 3:27 am
it's my test for BI position ,It's a real problem
July 3, 2013 at 5:38 am
engstevo (7/3/2013)
it's my test for BI position ,It's a real problem
It's SQL Server 101, and I'm surprised that the tests for a BI position can be this simple. If you cannot work at this level of simplicity, then you may wish to consider studying for a little longer before applying again. Real world BI problems and their solutions are unlikely to be within your capabilities at this time.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
July 3, 2013 at 8:50 am
Is this a test that you are setting up?
_________________________________________________________________________
SSC Guide to Posting and Best Practices
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply