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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:50:47+00:00 2026-05-17T19:50:47+00:00

To make a long story short… I’m building a web app in which the

  • 0

To make a long story short…

I’m building a web app in which the user can select any combination of about 40 parameters. However, for one of the results they want(investment experience), I have to extract information from a different table and compare the values in six different columns(stock exp, mutual funds exp, etc) and return only the highest value of the six for that specific record.

This is not the issue. The issue is that at runtime, my query to find the investment exp doesn’t necessarily know the account id. Considering a table scan would bring well over half a million clients, this is not an option. So what I’m trying to do is edit a copy of my main dynamically built query, but instead of returning 30+ columns, it’ll just return 2, the accountid and experienceid (which is the PK for the experience table) so I can do the filtering deal.

Some of you may define dynamic SQL a little different than myself. My query is a string that depending on the arguments sent to my procedure, portions of the where clause will be turned on or off by switches. In the end I execute, it’s all done on the server side, all the web app does is send an array of arguments to my proc.

My over simplified code looks essentially like this:

declare @sql varchar(8000)
set @sql = 
'select [columns]
into #tempTable
from [table]
[table joins]' + @dynamicallyBuiltWhereClause

exec(@sql)

after this part I try to use #tempTable for the investment experience filtering process, but i get an error telling me #tempTable doesn’t exist.

Any and all help would be greatly appreciated.

  • 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-17T19:50:48+00:00Added an answer on May 17, 2026 at 7:50 pm

    The problem is the scope of your temp table only exists within the exec() statement. You can transform your temp table into a “global” temp table by using 2 hash signs -> ##tempTable. However, I wonder why you are using a variable @dynamicallyBuiltWhereClause to generate your SQL statement.

    I have done what you are doing in the past, but have had better success generating SQL from the application (using C# to generate my SQL).

    Also, you may want to look into Table Variables. I have seen some strange instances using temp tables where an application re-uses a connection and the temp table from the last query is still there.

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

Sidebar

Related Questions

I'm going to make a long story short. It's been a while that I
It's hard to describe the whole problem but to make a long story short,
I'm trying to make a WCF service that will work with JSON-P (long-story short,
So long story short I have an object model in which several different entity
To make a long story short, I need to to create a shortcut to
Long story short: I'm trying to write an app that'll dump IE's history to
I'll try to make a long story short: I want to call a method
To make a long story short, my terminal was not working so a forum
To make a long story short, it looks as if I am going to
To make long story short: each of my tabs has its own form, so

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.