Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6635871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:06:41+00:00 2026-05-25T23:06:41+00:00

When I create areport in VS 2008 and try to use this stored procedure

  • 0

When I create areport in VS 2008 and try to use this stored procedure it appears I get only one record that looks like from insert command. What I want to get back is record from #WIP

BEGIN
SET NOCOUNT OFF


DECLARE @BeginDate datetime 
DECLARE @EndDate datetime --- Make sure month no 12 
Declare @NextMonth INT
set @NextMonth = @Month + 1  --- Make sure month no 12
set @BeginDate = convert(datetime, convert(varchar(4),@Year) + right('00' + convert(varchar(2),@Month),2) + '01' ) ;
set @EndDate = convert(datetime, convert(varchar(4),@Year) +  right('00' + convert(varchar(2),@NextMonth),2) + '01' ) ;

DECLARE @OwnerName nvarchar(50) 
DECLARE @Value numeric(18,2)
DECLARE @Hours numeric(18,2)
DECLARE @Expenses numeric(18,2)
DECLARE @Discount numeric(18,2)
DECLARE @InvoceTotal numeric(18,2)
DECLARE @Progress numeric(18,2)
DECLARE @ActualBilled numeric(18,2)
DECLARE @MyCursor CURSOR
Create Table #WIP (
    OwnerName varchar(50)
    ,BeginWIP numeric(18,2) 
    ,EndingWIP numeric(18,2)            
    ,PeriodAll numeric(18,2)            
    ,PeriodCurent numeric(18,2)             
    ,UnnatachedTime numeric(18,2) 
    ,Progress numeric(18,2) 
    ,Discount numeric(18,2)             
    ,NewHours numeric(18,2) 
    ,FeesStandard numeric(18,2) 
    ,ActualBill numeric(18,2) 
    ,Expenses numeric(18,2) 
    ,TotalInvoice numeric(18,2)             
    ,Real numeric(18,2) )   
SET @MyCursor = CURSOR 
    FOR
            select a.owneridname 
            ,Sum(ISNULL(t1.tcpm_hoursentered,0))  as hrs ,SUM(t1.tcpm_billingatstandardrate) as Standardbilled
            ,SUM(t1.tcpm_ActualBilledAmount) as ActualBilled
            ,SUM(t1.tcpm_actualbilledamount) as Invoicetotal
            from Filteredtcpm_timeItemValue t1
                    inner join Filteredtcpm_businessperiod b on t1.tcpm_businessperiodid = b.tcpm_businessperiodid
                    inner join FilteredSalesOrder s  on t1.tcpm_projectid = s.salesorderid
                    inner join FilteredAccount a on s.accountid = a.accountid and a.statecode=0
                    where b.tcpm_startdate >= @BeginDate 
                        and t1.tcpm_lastwipaction not in ('267120007','267120008','267120009') and  t1.tcpm_hoursentered IS not null
                group by a.owneridname      

    --OPEN @MyCursor 
    FETCH NEXT FROM @MyCursor INTO @OwnerName,@Hours,@Value,@ActualBilled,@InvoceTotal

    WHILE @@FETCH_STATUS = 0 
    BEGIN 
        FETCH NEXT FROM @MyCursor 
        IF EXISTS(select 1 from #WIP  where OwnerName = @OwnerName)
         BEGIN
            UPDATE #WIP 
            SET PeriodCurent=ISNULL(@Value,0)
            ,NewHours= @Hours
            ,ActualBill=@ActualBilled
            ,TotalInvoice=@InvoceTotal
             WHERE OwnerName = @OwnerName
         END
        IF NOT EXISTS(select 1 from #WIP  where OwnerName = @OwnerName)
         BEGIN
            INSERT INTO #WIP (OwnerName ,NewHours,ActualBill,TotalInvoice,PeriodCurent) 
                VALUES(@OwnerName,@Hours,@ActualBilled,@InvoceTotal,ISNULL(@Value,01)) 
         END         
        FETCH NEXT FROM @MyCursor INTO @OwnerName,@Hours,@Value,@ActualBilled,@InvoceTotal
    END     
select OwnerName ,BeginWIP,NewHours,ActualBill,TotalInvoice,PeriodCurent,UnnatachedTime  From #WIP

END

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:06:42+00:00Added an answer on May 25, 2026 at 11:06 pm

    You have a lone FETCH NEXT with no into at the top of your while loop.

    WHILE @@FETCH_STATUS = 0 
    BEGIN 
        FETCH NEXT FROM @MyCursor
    

    It is creating a result set for every other row in your cursor. Comment it out and I think you will get what you want.

    Also because of the extra fetch, you are only processing every other row of the cursor. If that was you intent, then you will need to add an into to the fetch and push thoes values into variables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When you try to create this proc on MS SQL Server 2008 and try
I have a report that I created with Crystal Reports 2008. This report uses
When you create a report using SQL Server Reporting Services 2008 (SP1), that uses
I need to create a report that looks like the following (WE is week-ending
Problem When you create a report (RDLC) the datasource seems to be only this
I need to create a report using SSRS 2008 that will show the top
How do I create a report (RDL file) using VS 2008. I created one
I am trying to create a report in SSRS2000 that will query an ORACLE
I am trying to create a report that has a summary for each group.
I have to create a report on Microsoft Reports in Visual Studio 2008. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.