Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Not returning Temp Table Data

Author  Topic 

ravininave
Posting Yak Master

111 Posts

Posted - 2011-12-08 : 21:38:12
Procedure not returning the data from Temp Table.
ALTER PROCEDURE [dbo].[FetchGroupComm]
(@AgentCode int,@FromDate datetime,@ToDate datetime)
AS
BEGIN
DECLARE @RowNo int,
@MainID int,
@tAmount float,@eComm float,@eTDS float,@eNet float

SET @RowNo = 1

DECLARE @DateTable AS TABLE (RowNo int IDENTITY(1,1),MainID int)
DECLARE @OutTable AS TABLE (RowNo int IDENTITY(1,1),tAmount float,eComm float,eTDS float,eNet float)

INSERT INTO @DateTable
Select MainID from Comms where IssueDate >=@FromDate and IssueDate <=@ToDate and AgentCode = @AgentCode group by MainID;
SELECT * FROM @DateTable
WHILE @RowNo < = ( SELECT MAX(RowNo) FROM @DateTable)
BEGIN
SET @tAmount=0
SET @eComm =0
SET @eTDS =0
SET @eNet =0
Select @MainID=MainID from @DateTable Where RowNo = @RowNo
Select @tAmount =COALESCE(round(sum(vAmount),2),0),@eComm = COALESCE(round(sum(Comm),2),0) ,@eTDS = COALESCE(round(sum(LessTDS),2),0) ,@eComm = COALESCE(sum(round(NetComm,2)),0) from Comms where IssueDate >=@FromDate and IssueDate <=@ToDate and MainID = @MainID and AgentCode = @AgentCode;
if @tAmount > 0
BEGIN
INSERT INTO @OutTable (tAmount,eComm,eTDS,eNet) VALUES (@tAmount ,@eComm ,@eTDS,@eNet)
END
SET @RowNo = @RowNo +1
END
Select * from @OutTable
END



VB6/ASP.NET
------------------------
http://www.nehasoftec.com

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-12-08 : 23:41:31
you don't need to use while loop

Select MainID,
tAmount = COALESCE(round(sum(vAmount),2),0),
eComm = COALESCE(round(sum(Comm),2),0),
eTDS = COALESCE(round(sum(LessTDS),2),0),
eNet = COALESCE(sum(round(NetComm,2)),0)
from Comms
where IssueDate >=@FromDate
and IssueDate <=@ToDate
and AgentCode = @AgentCode;
group by MainID



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

ravininave
Posting Yak Master

111 Posts

Posted - 2011-12-09 : 00:48:41
quote:
Originally posted by khtan

you don't need to use while loop

Select MainID,
tAmount = COALESCE(round(sum(vAmount),2),0),
eComm = COALESCE(round(sum(Comm),2),0),
eTDS = COALESCE(round(sum(LessTDS),2),0),
eNet = COALESCE(sum(round(NetComm,2)),0)
from Comms
where IssueDate >=@FromDate
and IssueDate <=@ToDate
and AgentCode = @AgentCode;
group by MainID



KH
[spoiler]Time is always against us[/spoiler]





No, I must have to use loop. Kindly suggest me why it's not returning data from temp table

VB6/ASP.NET
------------------------
http://www.nehasoftec.com
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-12-09 : 01:03:00
quote:
No, I must have to use loop

any particular reason why ?
quote:
Kindly suggest me why it's not returning data from temp table

I don't have access to the data to see where is the problem. Put some debug statement in there to see if your SELECT statement returns any records.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -