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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:19:52+00:00 2026-05-20T06:19:52+00:00

Okay basically I am creating a stored procedure that will return data for our

  • 0

Okay basically I am creating a stored procedure that will return data for our coldfusion power search.

I created a view, to hold data from multiple tables, with the same column names returned of course.

Then in my stored procedure i have created a simple temporary table like this….

    CREATE TABLE #TempSearchResults
(
    search_id int identity,
    id integer,
    type varchar(20),
    title varchar(50),
    url varchar(250),
    rank integer
)

Then I added an index to it, in my perhaps limited experience as a way to improve performance.

CREATE UNIQUE INDEX idx on #TempSearchResults (search_id)

Then i did my select into massive query

insert into #TempSearchResults
select id, type, title, url, rank + 1200 as rank
from my view
where company_id = @company_id
and title like @keyword
union all
select id, type, title, url, rank + 1100 as rank
from my view
where company_id = @company_id
and title like @keyword
and description like @keyword

and it goes on like that having different rank math values for where it found the keyword in the tables.

And at the end it does…

select id, type, title, url, rank
from #TempSearchResults
group by id, type, title, url, rank
order by rank desc, title asc;

Now when I test that stored procedure in coldfusion, it seems to take very long.

So I am thinking, either I am using temp tables wrong or incompletely for optimal performance.

Or perhaps I should switch to table variables…

But I was just reading…Temp Tables VS Table Variables

Funny thing is, this stored procedure seems to be slower than me running the query directly via coldfusion, which I prefer not to.

I am hoping for optimal performance….

Thank you…

Below is the basic logic or code for the view I am using.

select some field as id, some field as title, some field as description, 'url link' as url, 1 as rank
from table a
union
select some field as id, some field as title, some field as description, 'url link' as url, 1 as rank
from table b
union
select some field as id, some field as title, some field as description, 'url link' as url, 1 as rank
from table c

Etc like that. I can’t reveal the exact details, as that would be a security breach. I hope that makes it clearer.

  • 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-20T06:19:53+00:00Added an answer on May 20, 2026 at 6:19 am

    I see no need to use a temporary table or table variable at all. You can just write

    select id, type, title, url, rank
    from (
        select id, type, title, url, rank + 1200 as rank 
        from my view 
        where company_id = @company_id and title like @keyword 
    
        union all 
    
        select id, type, title, url, rank + 1100 as rank 
        from my view 
        where company_id = @company_id and title like @keyword and description like @keyword
    ) as t
    group by id, type, title, url, rank
    order by rank desc, title asc;
    

    Edit:

    Replacing UNION ALL by UNION, this can be simplified to

    select id, type, title, url, rank + 1200 as rank 
    from my view 
    where company_id = @company_id and title like @keyword 
    
    union 
    
    select id, type, title, url, rank + 1100 as rank 
    from my view 
    where company_id = @company_id and title like @keyword and description like @keyword
    
    order by rank desc, title asc;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay so basically I'm trying to do a depth-first search for a mini-peg solitaire
Okay, basically, I have formed a mySQL query which returns a data set all
Okay, so basically I want to be able to retrieve keyboard text. Like entering
Okay I know I asked about this before, and the answer was basically cache
Okay, here's the scenario. I have a utility that processes tons of records, and
Okay i've seen this done somewhere before where you have a function that takes
Okay basically here's where I'm at. I have a list of PropertyDescriptor objects. These
Okay basically, I'm designing and developing a fairly complicated website which revolves around the
Okay so basically : i have this simple example: main.cpp using namespace VHGO::Resource; std::list<BaseTable*>
Okay basically /// <summary> /// Sends the process. /// </summary> /// <param name=MD5>The M

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.