February 3, 2015 at 11:54 pm
i wanna create a procedure for P& L cost sheet , i had done that procedure now include a cursor instead of replacing sql queries .
create procedure pl_test
@fmdate datetime,
@todate datetime,
@categ varchar(2000)
begin
create table #temp
(
responsibility varchar(500),
Dept varchar(500),
category varchar(500),
Fs_accounts varchar(800),
Actuals float,
)
insert into #temp(
responsibility,
dept,
category,
Fs_accounts,
Actuals
)
select column1,columns2,columns3,columns4,columns5 from fms_accounts
if @categ is null or @categ=' '
begin
select
responsibility,
dept,
category,
round((Max(Actuals)/100000),1,2)as Actuals from #temp
group by
responsibility,
dept,
category
end
else
begin
select category,fs_accounts,Actuals from #temp where category = @catagory group by category,fs_accounts,Actuals
end
drop table #temp
end
how to include cursor on if part and else part
February 4, 2015 at 1:32 am
Cursors are notoriously slow so I would advise avoiding them except in a specific instance.
It would help if you could post some sample data and the output you are expecting as that will help us deliver a solution.
_________________________________________________________________________
SSC Guide to Posting and Best Practices
February 4, 2015 at 6:25 am
What are you trying to do with the cursor? The way the question is stated I almost think you are looking for dynamic SQL.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply