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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:46:57+00:00 2026-05-27T01:46:57+00:00

I have dynamic query I want to get two output parameters from it I

  • 0

I have dynamic query I want to get two output parameters from it I used the following code , but the output parameters return null

declare @query nvarchar(max);
declare @result int; 
declare @type int
declare @mainVarcharLength int; 

set @query = 'select   count(*) ,  Type_Code from Customers   WHERE Customers.Cust_Name =  ''CUSTOMER 99''  '
set @query = @query + '  and Cus_Is_Active = 1  Group BY   Type_Code';
select  @query

EXEC sp_executesql @query, N'@result int OUTPUT,  @type int OUTPUT', @result,  @type

select @result
select @type

How to solve that , and how to pass multiple output parameters

  • 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-27T01:46:58+00:00Added an answer on May 27, 2026 at 1:46 am

    You need to state what is being allocated to the outputs;

    set @query = 'select @result=count(*), @type=Type_Code from Customers ....'

    then decorate the outputs with OUTPUT;

    EXEC sp_executesql @query,   
        N'@result int OUTPUT, @type int OUTPUT',
        @result OUTPUT, 
        @type OUTPUT
    

    (You could also pass ''CUSTOMER 99'' as an input)

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

Sidebar

Related Questions

Hi I have a really complicated dynamic query that i want to use to
I need to used dynamic order query in mysql and i have successfully achieved
i want to create the following query in expression trees: var test = from
I have a method that I use to return a dynamic query. This method
I want to have dynamic parameters, so I made these models : class DynamicObject(models.Model):
I want to query the datastore for Expando entities that have a certain dynamic
I have a dynamic amount of div's being returned from a query, all with
I have a dynamic query that returns around 590,000 records. It runs successfully the
I have a dynamic query which I call and I put the Result set
In my web application, I have a dynamic query that returns huge data to

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.