Hello
SQL Server 2000
Maybe you help me with this.
I have to write a stored procedure.
I have to print:
2010 until last full month (May)
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Total
jobs
kg
sales
cost
profit
margin
2009 all
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Total
jobs
kg
sales
cost
profit
margin
I have this:
CREATE procedure [dbo].[Z_comp] @Year int as
DECLARE @DateStart datetime
DECLARE @DateEnd datetime
DECLARE @c_result INT
SET @DateStart = cast(@Year-1 as varchar(4))+'0101'
-- Set date start to be 01/01/year-1 00:00:00
SET @DateEnd = cast(@Year+1 as varchar(4))+'0101'
-- Set date end to be 01/01/year+1 00:00:00
IF @Year= YEAR(GETDATE())
-- Current year, must get last full month
BEGIN
SET @DateEnd = CAST(CONVERT(varchar(8),DateAdd(dd,-DAY(GetDate()), GetDate()), 112) as datetime) + 1
END
SELECT …..
Select brings in the report every record; after that I make the sum, profit, ….., margin (if sum sales<>0 then sum profit/sum sales*100 for each month), for each year
I want to obtain the sums, …., margin from the stored procedure. How shall I write this?
Thank you
SQL Server 2000
Maybe you help me with this.
I have to write a stored procedure.
I have to print:
2010 until last full month (May)
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Total
jobs
kg
sales
cost
profit
margin
2009 all
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Total
jobs
kg
sales
cost
profit
margin
I have this:
CREATE procedure [dbo].[Z_comp] @Year int as
DECLARE @DateStart datetime
DECLARE @DateEnd datetime
DECLARE @c_result INT
SET @DateStart = cast(@Year-1 as varchar(4))+'0101'
-- Set date start to be 01/01/year-1 00:00:00
SET @DateEnd = cast(@Year+1 as varchar(4))+'0101'
-- Set date end to be 01/01/year+1 00:00:00
IF @Year= YEAR(GETDATE())
-- Current year, must get last full month
BEGIN
SET @DateEnd = CAST(CONVERT(varchar(8),DateAdd(dd,-DAY(GetDate()), GetDate()), 112) as datetime) + 1
END
SELECT …..
Select brings in the report every record; after that I make the sum, profit, ….., margin (if sum sales<>0 then sum profit/sum sales*100 for each month), for each year
I want to obtain the sums, …., margin from the stored procedure. How shall I write this?
Thank you