April 18, 2012 at 11:03 am
Not enough information to really help. Looks like there may be several things wrong with the code.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ and follow the instructions on what information to post and how to post it. The more information you provide, the better answers you will get.
April 18, 2012 at 11:23 am
where should i put fetch_next in body
April 18, 2012 at 11:35 am
riya_dave (4/18/2012)
where should i put fetch_next in body
This will help you with the code http://remidian.com/mssql/t-sql/cursors-in-tsql.html however if you post the full code of your SP and the table definitions (DDL) and some sample data we may be able to write your SP with out the cursor. cursors are row by row and SQL works best in almost every situation with a set based solution.
and since you are not passing any thing to pbdashboard as your code is written now you dont need the cursor.
For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]
Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
Jeff Moden's Cross tab and Pivots Part 1[/url]
Jeff Moden's Cross tab and Pivots Part 2[/url]
April 18, 2012 at 11:44 am
thanks for the link,i got it
April 18, 2012 at 2:24 pm
ok.simple question.my cursor return one value that i need to take in temp table
simply i can insert into temp table(cursor return value using local variable)
April 18, 2012 at 2:26 pm
riya_dave (4/18/2012)
ok.simple question.my cursor return one value that i need to take in temp tablesimply i can insert into temp table(cursor return value using local variable)
Not enough information to really help.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ and follow the instructions on what information to post and how to post it. The more information you provide, the better answers you will get.
April 18, 2012 at 2:38 pm
OK. I PUT FETCH_NEXT LIKE THIS
STILL NOT WORKING GOING ENDLESS.
declare @P1 nvarchar(32)
declare @mtd2 float
declare c1 CURSOR FOR
select account, MTD from #temp2
open c1
FETCH NEXT FROM c1
INTO @P1,@mtd2
WHILE @@FETCH_STATUS = 0
begin
if(@mtd2 IS NULL )
BEGIN
declare @IRR2 float
EXEC pdashboard
select @IRR2 = IRR from pdashboard
SELECT @IRR2 as Last1month
fetch next from c1 into @P1,@MTD2
END
ELSE
BEGIN
select @mtd2 as last2month
fetch next from c1 into @P1,@MTD2
END
END
Any help?
April 18, 2012 at 2:40 pm
Look closely at where you put your fetch next. It is inside an else block.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
April 18, 2012 at 2:40 pm
riya_dave (4/18/2012)
OK. I PUT FETCH_NEXT LIKE THISSTILL NOT WORKING GOING ENDLESS.
declare @P1 nvarchar(32)
declare @mtd2 float
declare c1 CURSOR FOR
select account, MTD from #temp2
open c1
FETCH NEXT FROM c1
INTO @P1,@mtd2
WHILE @@FETCH_STATUS = 0
begin
if(@mtd2 IS NULL )
BEGIN
declare @IRR2 float
EXEC pdashboard
select @IRR2 = IRR from pdashboard
SELECT @IRR2 as Last1month
fetch next from c1 into @P1,@MTD2
END
ELSE
BEGIN
select @mtd2 as last2month
fetch next from c1 into @P1,@MTD2
END
END
Any help?
Not enough information to really help.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ and follow the instructions on what information to post and how to post it. The more information you provide, the better answers you will get.
April 18, 2012 at 2:47 pm
i am also putting in if statement and after end of if,
nothing is working out.
where should i put
April 18, 2012 at 2:49 pm
Basic cursor structure.
fetch_next
while fetch_status
begin
--do some stuff here
fetch_next
end
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
April 18, 2012 at 2:51 pm
declare @P1 nvarchar(32)
declare @mtd2 float
declare c1 CURSOR FOR
select account, MTD from #temp2
open c1
FETCH NEXT FROM c1
INTO @P1,@mtd2
WHILE @@FETCH_STATUS = 0
begin
if(@mtd2 IS NULL )
BEGIN
declare @IRR2 float
EXEC pdashboard
select @IRR2 = IRR from pdashboard
SELECT @IRR2 as Last1month
END
ELSE
BEGIN
select @mtd2 as last2month
END
fetch next from c1 into @P1,@MTD2
END
this is fine ???
April 18, 2012 at 3:08 pm
riya_dave (4/18/2012)
declare @P1 nvarchar(32)declare @mtd2 float
declare c1 CURSOR FOR
select account, MTD from #temp2
open c1
FETCH NEXT FROM c1
INTO @P1,@mtd2
WHILE @@FETCH_STATUS = 0
begin
if(@mtd2 IS NULL )
BEGIN
declare @IRR2 float
EXEC pdashboard
select @IRR2 = IRR from pdashboard
SELECT @IRR2 as Last1month
END
ELSE
BEGIN
select @mtd2 as last2month
END
fetch next from c1 into @P1,@MTD2
END
this is fine ???
again not enough information. what does EXEC pdashboard do and can you post your ddl and table definitions so we can better help you.
For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]
Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
Jeff Moden's Cross tab and Pivots Part 1[/url]
Jeff Moden's Cross tab and Pivots Part 2[/url]
April 18, 2012 at 3:09 pm
ok. i tried to put everwhere nothing is working
plz help
where should i put it
April 18, 2012 at 3:17 pm
Okay, I have tried.
You want help, you have to give us more than the little tidbit pieces you continue to post. I really want you to look at your posts and tell me if you knew nothing about what was being done, could you help that person with what is there.
We can't. We can't see what you are doing, we can't see all of your code, we can't see your data, we don't even know what it is you are trying to accomplish.
You want help, you have to tell use everything we need to know to understand your environment and what it is you are trying to accomplish.
You know that link to that article I kept posting. Go read it before you post anything more on this thread.
Viewing 15 posts - 16 through 30 (of 67 total)
You must be logged in to reply to this topic. Login to reply