SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Stored Proc
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Emile
Starting Member

South Africa
5 Posts

Posted - 10/23/2012 :  07:07:02  Show Profile  Reply with Quote
hello?
I'm very new to T-SQL, I work part time as a programmer.
I have difficulty in adapting a stored proc to recieve a parameter from an exact replicant of itself.

This is the initial stored proc :
alter procedure mlmMeterUsageStats
@Action int=0
as
begin
set NOCOUNT on

declare
@Tot int,
@Date datetime

set @Date = substring(convert(varchar(10),getdate(),111),1,8) + '01'


select @Tot = count(*)
from mlmMeter
where TypeId = 0
and Disabled = 0

select CalcDate, left(datename(month,CalcDate),3) + ' ' + right(cast(year(CalcDate) as varchar(10)),2) as Descr,
sum(case when IsEstimate=0 then 1 else 0 end) as Actual,
sum(case when IsEstimate=1 and NoteCode >= 0 then 1 else 0 end) as Est,
sum(case when IsEstimate=1 and NoteCode < 0 then 1 else 0 end) as Calc,
@Tot-count(*) as NoRead, convert(varchar(10),getdate(),111) as TheDate, @Tot as Tot,
'<tr><td><b>' + left(datename(month,CalcDate),3) + ' ' + right(cast(year(CalcDate) as varchar(10)),2) +
'</td><td bgcolor="green" colspan="' + cast(sum(case when IsEstimate=0 then 1 else 0 end)*100/@Tot as varchar(10)) + '"><br></td><td bgcolor="red" colspan="' + cast(sum(case when IsEstimate=1 and NoteCode >= 0 then 1 else 0 end)*100/@Tot as varchar(10)) + '"><br></td><td bgcolor="yellow" colspan="' + cast(sum(case when IsEstimate=1 and NoteCode < 0 then 1 else 0 end)*100/@Tot as varchar(10)) + '"><br></td><td bgcolor="black" colspan="' + cast(100 - (sum(case when IsEstimate=1 and NoteCode < 0 then 1 else 0 end)*100/@Tot) - (sum(case when IsEstimate=0 then 1 else 0 end)*100/@Tot) - (sum(case when IsEstimate=1 and NoteCode < 0 then 1 else 0 end)*100/@Tot) as varchar(10)) + '"><br></td></tr>'
as HTML
from mlmMeter M
join mlmMeterUsage U
on M.MeterId = U.MeterId
and M.Disabled = 0
and M.TypeId = 0
and U.CalcDate >= dateadd(month,case when @Action = 0 then -11 else -2 end,@Date)
group by CalcDate, left(datename(month,CalcDate),3) + ' ' + right(cast(year(CalcDate) as varchar(10)),2)
order by CalcDate desc

return 0
end


Then I need to create a proc that will recieve the CalcDate

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 10/23/2012 :  07:23:53  Show Profile  Reply with Quote
What do you want your new stored procedure do? Should it do exactly the same thing as the current stored procedure, except it should accept a date? Or are you trying to change the behavior of the stored procedure?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 10/23/2012 :  18:38:29  Show Profile  Reply with Quote
hmm...what does this mean?

I have difficulty in adapting a stored proc to recieve a parameter from an exact replicant of itself.
why do you need same procedure twice?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.15 seconds. Powered By: Snitz Forums 2000