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

  • Home
  • SEARCH
  • 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 8515555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:10:49+00:00 2026-06-11T05:10:49+00:00

I need to execute result (already in form of SQL) itself of an SQL

  • 0

I need to execute result (already in form of SQL) itself of an SQL query to get the final result.

So, it should be like, in first query I execute

Select Top(1) RequiredQuery as ReqQry from EPMaster 

I’ll get another query in result in ReqQry that will then be executed in form another query to get the final result.

The second query will also require some parameters to be passed at where clause, like when I do:

Select Top(1) RequiredQuery as ReqQry 
from EPMaster 
--ReqQry after its execution returns:
Select Top(1) (FirstName + ' ' + LastName) as FullName 
from DPMaster 
where DmID = @DomainID and PnID = @PersonID

I’ll be passing the Params @DomainID and @PersonID from my C# project’s DAL layer.

So I guess it should be done with the help of a stored procedure.

—————–More Explanation————-

Here, one SQL statement is executed to get the next SQL statement which will be the resultant of the former statement. When you execute 1st query, you get 2nd query in result, which you execute again to get the final result

The second query needs 2 parameters to execute that are @DomainID and @PersonID which will be passed by me from my C# Project. So, if I make a stored procedure for handeling all this and pass the required parameters, along with the 1’st query from my project, it should first execute 1st query then execute 2nd query (with parameters PersonID and DomainID) that was received as result of 1st query, after which I get the final result.

  • 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-11T05:10:51+00:00Added an answer on June 11, 2026 at 5:10 am

    You should use Dynamic SQL, to get running the returned nvarchar(max) query string from the first procedure / query.

    Edit:

    DECLARE @ResultOfTheFirstQuery nvarchar(max)
    
    SELECT @ResultOfTheFirstQuery = (Select Top(1)RequiredQuery 
                                     as ReqQry from EPMaster)
    
    exec sp_executeSql @ResultOfTheFirstQuery
    

    Or if you need a complex logic, you can write an other SP, which can heve a return value:

    DECLARE @ResultOfTheFirstQuery nvarchar(max)
    
    SELECT @ResultOfTheFirstQuery = FirstStoredprocedure @params
    
    exec sp_executeSql @ResultOfTheFirstQuery
    

    Here is an already well answered question how to get the paramater return. You can use RETURN or OUTPUT parameter.

    Here is how to use the sp_executeSql

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

Sidebar

Related Questions

I need to execute a SQL Query between two databases. Example: SELECT * from
I need execute an SQL query in ORACLE it takes a certain amount of
I need to execute a subquery in a select clause with Apache Openjpa 2.
I need execute some code before Windows shutdown process each time. So, I want
I need to execute some commands in batch mode (e.g., via Rscript). They work
I need to execute code at intervals, sometimes 10 seconds, sometimes 5 minutes. The
I need to execute a script in the background through a service. The service
I need to execute a command 100-200 times, and so far my research indicates
I need to execute the given commands as root and sudo user using Java.
I need to execute a bash script on boot. To do so I created

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.