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 8474713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:41:53+00:00 2026-06-10T17:41:53+00:00

I have a situation, where I am executing a stored procedure and fetching results

  • 0

I have a situation, where I am executing a stored procedure and fetching results in my c# code which returns 55 records, now I have a column in the row which needs to be displayed as a result of executing another sql query. I have tried all means, but couldn’t figure out how to achieve. Please help.

The C# code where I call the procedure which works fine is:

public static MonthlyFinancialReportCollection GetList(SASTransaction withinTransaction)
{
    MonthlyFinancialReportCollection records = null;

    using (DataSet ds = Helpers.GetDataSet("ShowPremiumCalcReport", withinTransaction))
    {
        if (ds.Tables.Count > 0)
        {
            records = new MonthlyFinancialReportCollection();

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                if (!string.IsNullOrEmpty(dr[0].ToString())) 
                     records.Add(FillDataRecord(dr));                        
            }
        }
    }

    return records;
}

Now I want to run a query, against the called procedure in the above function, so it will fill the one of the column with calculated result of the query.

select 
    Sum(WorkingHours.WHO_Amount * dbo.PremiumLevel.PLE_Premium) as Snr_Teaching_Amt
from policy, policyline, coveroption,
     premiumlevel, WorkingHours
where policy.pol_id=policyline.pli_pol_id 
and   policyline.pli_cop_seniorteachingcoverid=coveroption.cop_id 
and   premiumlevel.ple_own_id=policy.pol_own_id 
and   premiumlevel.ple_sca_id=coveroption.cop_sca_id 
and   WorkingHours.who_pos_id=policyline.pli_pos_id
and   pol_dcsf=row["snr teaching staff"]`
  • 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-06-10T17:41:54+00:00Added an answer on June 10, 2026 at 5:41 pm

    The slowest and easiest way:

    • Make your second query a stored procedure which accepts “snr teaching staff”
      As a parameter.
    • Add a new column to your DataTable from first query using:
      ds.Tables[0].Columns.Add(“Snr_Teaching_Amt”, typeof(decimal));
    • Create a SqlCommand and a SqlParameter for the second stored procedure you created.
    • Loop the DataTable and put “snr teaching staff” in value of SqlParameter.
    • Run the SqlCommand using ExecuteScalar, the returned value is the result of your second query which you can keep in your created column.

    However I don’t recommend this way because you’ll have 55 + 1 server round trips which is not cool.

    The in-between way:

    Since your second query returns a single value, make the second query a Sql function. You can call it in the first procedure like:

    SELECT *, dbo.MyFunction([snr teaching staff]) AS Snr_Teaching_Amt FROM ...
    

    This will have better performance and is easier to maintain.
    However I agree with Massanu, you can combine the procedures using sub queries. Best of luck 😉

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

Sidebar

Related Questions

I have situation, where running a query that filters by an indexed column in
I have situation in which I read a record from a database. And if
I'm struggling with correct procedure for executing SQL query. Basically, I have text field
I have a situation which resembles the following: let mutable stopped = false let
I have a situation where I have six possible situations which can relate to
Using Python 2.7 Situation: I have some piece of Python code (that the user
i have situation like this: class IData { virtual void get() = 0; virtual
I have situation where I need to change the order of the columns/adding new
I have situation where a user can manipulate a large set of data (presented
I have situation like this: user submits form with action='/pay' in '/pay' I have

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.