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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:02:24+00:00 2026-05-18T11:02:24+00:00

I have 3 tables : table_product (30 000 row) ——— ID label _ table_period

  • 0

I have 3 tables :

table_product (30 000 row)
---------
ID
label

_

table_period (225 000 row)
---------
ID 
date_start
date_end
default_price
FK_ID_product

and

table_special_offer (10 000 row)
-----
ID
label
date_start,
date_end,
special_offer_price
FK_ID_period

So I need to load data from all these table, so here it’s what I do :
1/ load data from “table_product” like this

select *
from table_product
where label like 'gun%'

2/ load data from “table_period” like this

select *
from table_period
where FK_ID_product IN(list of all the ids selected in the 1)

3/ load data from “table_special_offer” like this

select *
from table_special_offer
where FK_ID_period IN(list of all the ids selected in the 2)

As you may think the IN clause in the point 3 can be very very big (like 75 000 big), so I got a lot of chance of getting either a timeout or something like ” An expression services limit has been reached”.

Have you ever had something like this, and how did you manage to avoid it ?

PS :
the context : SQL server 2005, .net 2.0
(please don’t tell me my design is bad, or I shouldn’t do “select *”, I just simplified my problem so it is a little bit simpler than 500 pages describing my business).

Thanks.

  • 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-18T11:02:24+00:00Added an answer on May 18, 2026 at 11:02 am

    In finally have my answer : table variable (a bit like @smirkingman’s solution but not with cte) so:

    declare @product(id int primary key,label nvarchar(max))
    declare @period(id int primary key,date_start datetime,date_end datetime,defaultprice real)
    declare @special_offer(id int,date_start datetime,date_end datetime,special_offer_price real)
    
    insert into @product
    select * 
    from table_product
    where label like 'gun%'
    
    insert into @period
    select * 
    from table_period
    where exists(
    select * from @product p where p.id = table_period.FK_id_product
    )
    
    insert into @special_offer
    select * 
    from table_special_offer
    where exists(
    select * from @period p where p.id = table_special_offer.fk_id_period
    )
    
    select * from @product
    select * from @period
    select * from @special_offer
    

    this is for the sql, and with c# I use ExecuteReader, Read, and NextResult of the class sqldatareader

    http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.aspx

    I got all I want :
    – my datas
    – i don’t have too much data (unlike the solutions with join)
    – i don’t execute twice the same query (like solution with subquery)
    – i don’t have to change my mapping code (1row = 1 business object)

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

Sidebar

Related Questions

I have a two tables cstomers and orders table. These tables contain 20,000 records
I have 2 tables like this: Stock Table product_id bigint(20) qty float Sales Table
I have a question. I have here 2 tables table 1 : products product_id
I have 2 tables product and history product table: id name type price location
I have 2 tables. Table_1 has product 3 rows : ID, Quantity and Price.
My prob in brief: I have two tables namely category and product. table: category
I have tables Product ( ID, CategoryID, ... ) Category ( ID, Name, ..
I have two tables: This is table1: product_id|product_desc|product_name|product_s_desc This is table2: product_price_id|product_id|product_price Now I
I have 2 tables and a view. In product_oper I have some products that
Lets say we have 3 tables: products, attributes and details. products id name price

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.