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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:18:22+00:00 2026-05-15T19:18:22+00:00

Here is my problem. I am creating 4 temp tables to count specific types

  • 0

Here is my problem. I am creating 4 temp tables to count specific types of boxes and an employee’s hours. Given a beginning date and ending date we want to know total boxes of each type (1, 2, and 3) and their total hours worked in that time period. All works perfectly if there is at least one of each type, but if only two types are present then I get a blank result for the entire final SELECT statement.

So, can a SELECT statement that contains an empty temp table in the FROM line cause everything else to return blank?

For example, the date range 6-1-10 to 6-10-10 returns 10 type 1 boxes, 12 type 2 boxes, 0 type 3 boxes, and 36 hours, but the result displayed is blank. But if it is extended one day and 15 type 3 boxes are included the query works.

SELECT Count(isnull(Box_Num,0)) as Box1, emp_num INTO #Box1
FROM  TEST.dbo.Prod_beta2
WHERE BoxType like '1' and time  > '06/01/10' + ' 12:01 AM'  and time  < '06/10/10' + ' 11:59pm' and emp_num like '10467'
group by emp_num


SELECT Count(isnull(Box_Num,0)) as Box2, emp_num INTO #Box2
FROM TEST.dbo.Prod_beta2
WHERE BoxType like '2' and time > '06/01/10' + ' 12:01 AM' and time < '06/10/10' + ' 11:59pm' and emp_num like '10467'
group by emp_num


SELECT count(isnull(box_num,0)) as Box3, emp_num INTO #Box3
from TEST.dbo.Prod_beta2
WHERE BoxType like '3' and time > '06/01/10' + '  12:01 AM' and time < '06/10/10' + ' 11:59pm' and emp_num like '10467'
group by emp_num


SELECT SUM(HOURS) as TotalHours, empid INTO #Hours
FROM TEST.dbo.Timeclock
where timein > '06/01/10' + ' 12:01 AM' and timein < '06/10/10' + ' 11:59pm' and empid like '10467'
group by empid


SELECT Box1, Box2, Box3, TotalHours
FROM #Box1, #Box2, #Box3, #Hours


DROP TABLE #Box1, #Box2, #Box3, #Hours
  • 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-15T19:18:22+00:00Added an answer on May 15, 2026 at 7:18 pm

    Yes. You are doing a Cartesian product which means you will have B1 * B2* B3 * H rows in the result.

    When B3 has no rows you are obviously multiplying by zero.

    The first three of your conditions can easily be combined (by the way what is the data type of BoxType and emp_num? If they are numeric then don’t use strings to avoid any unnecessary type conversion issues. Additionally your date logic seems to miss anything between 11:59pm to 12:01 AM. Is this intentional? Moreover you should probably use ISO date formats to avoid any issues if you ever change servers etc. )

    SELECT 
    Count(CASE WHEN BoxType = '1' THEN 1 ELSE NULL END) as Box1,
     Count(CASE WHEN BoxType = '2' THEN 1 ELSE NULL END) as Box2,
     Count(CASE WHEN BoxType = '3' THEN 1 ELSE NULL END) as Box3
    FROM  TEST.dbo.Prod_beta2
    WHERE BoxType in ('1','2','3') and time  > '06/01/10' + ' 12:01 AM'  and 
      time  < '06/10/10' + ' 11:59pm' and emp_num like '10467'
    group by emp_num
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

so here is the problem. I am currently creating an Android app that is
Okay, so here's my problem: We use FOP for creating pretty report output. We
I have a problem: (I wouldn't be here otherwise ;) I am creating an
Okay, so, here's what the problem is. I'm creating a flash site with each
date here my problem: String datetime = 2012-03-24 23:20:51; I know that that string
I am having problem creating a new directory inside my FTP using mkdir, here
Having a problem here with creating a child window with c++ and win32 api.
I've got a problem here. I'm creating a NSTrackingArea like this: NSTrackingArea *area =
I have a feeling I'm being thick, but here's my problem: I'm creating dynamic
I'm programmtically creating websites/users etc ... Here's the problem: When creating a website, I

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.