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

The Archive Base Latest Questions

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

UPDATE : This is what I did – set @dyn_sql = ‘ select @UserName=UserName

  • 0

UPDATE : This is what I did –

   set @dyn_sql = '
                        select
                                @UserName=UserName
                        from
                        (
                        select 
                                E.ID as EmployeeID,
                                E.UserName as Username
                            from   
                                Leaderboard K
                                    inner join Employee E on  K.EmployeeId = E.Id
                                    inner join INFO KD on KD.EmployeeId=E.Id
                                    where  E.CompanyId=4
                         ) as d1'
DECLARE @leaderboards TABLE
( 
 UserName varchar(50)
) 
set @params='@Employee_Id int, @UserName varchar(200) OUTPUT'
INSERT INTO @leaderboards (UserName)
EXEC sp_executesql @dyn_sql, @params,@EmployeeId=@Employee_Id OUTPUT,@UserName = @User_Name OUTPUT

SELECT * from @leaderboards

But this is not returning records although if I see the query is right and returns records..


Hi all, I am executing a dynamic sql statement using sp_executesql and this is what I am doing currently –

EXEC sp_executesql @dyn_sql, @params,@EmployeeId=@Employee_Id OUTPUT,@UserName = @User_Name OUTPUT

SELECT @Employee_Id AS EmployeeId,@User_Name AS UserName

But the above only gets me single value when I am getting a list of records if I run the dynamic sql query individually.How can I store the list of values returned by execution of my dynamic sql ?
and returns records..and returns records..But this

  • 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-16T23:20:06+00:00Added an answer on May 16, 2026 at 11:20 pm

    Via a temp table.

    [Update]

    declare @sql nvarchar(max)
      set @sql = '
    select 
        E.ID as EmployeeID, --doesn't really matter how you name them, it's the order that matters
        E.UserName as Username -- and this order should match the order of columns in the insert statement
    from   
        Leaderboard K
            inner join Employee E on  K.EmployeeId = E.Id
            inner join INFO KD on KD.EmployeeId=E.Id
            where  E.CompanyId=4
    '
    DECLARE @LeaderBoard TABLE
    ( 
        EmployeeId int, 
        UserName varchar(50)
    ) 
    INSERT INTO @LeaderBoard (EmployeeId, UserName)
    exec sp_executesql @sql
    
    select * from @LeaderBoard
    
    --Hurray, we made it!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update : This is no longer an issue from C# 6, which has introduced
SELECT lott.id as lottery_id,lott.abbr,lott.currency,payments.id as payment_id, payment_prizes.prize_id,prizes.name,prizes.currency as prizes_currency FROM lotteries lott JOIN lottery_payments
Update: This does work, I was being stupid :( i have the following extension
Update: This is, as I was told, no principle Python related problem, but seems
UPDATE: this is a repost of How to make shell scripts robust to source
UPDATE: This question is out of date, but left for informational purposes. Original Question
Update: This question was an epic failure, but here's the working solution. It's based
Update: This question is a duplicate of Are there any programming languages targeting PHP,
Update: This issue was not properly explored. The real issue lies within render :json
UPDATE: This is the working example. First we create a class to hold weekday,

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.