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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:39:13+00:00 2026-05-30T12:39:13+00:00

I need to be able to extract rows for a dataset in SSRS 2008

  • 0

I need to be able to extract rows for a dataset in SSRS 2008 using TSQL. I am using three tables product, stock, calls. product has a composite key of mfg and part_number and those fields are foreign keys in the other two tables. The calls table creates a row that sums the number of calls for a specific month and represents the month in the format yyyymm. What I want to do is to extract the last call for each part but I want to ignore the current month, so I have this:

select product.mfg, product.part_number, max(calls.yyyymm) last_call
from product inner join stock on product.mfg = stock.mfg 
and product.part_number = stock.part_number
left join calls on product.mfg = calls.mfg 
and product.part_number = calls.part_number
where stock.onhand > 0 and calls.yyyymm < '201202'

This works ok but there are around 65 records where the only call is in '201202'.

I have tried nullif(max(calls.yyyymm), null) instead of max(calls.yyyymm). I would think that a left join to the calls table would get it done, but it doesn’t seem to. I have also tried a couple of variations of a case statement in the select, namely:

case when max(calls.yyyymm) is not null then max(calls.yyyymm) else null end

What I ultimately want to do is create two data sets, one for in stock parts and one for calls on in stock parts, then use the lookup function in SSRS 2008 to create the report, but I want both sets to generate the same number of rows since this is a moving target. This is not my preferred way of doing this but our parts manager wants me to try to freeze the data at the end of each month, which is why I decided to try ignoring all calls for the current month. For each call in the current month I want to use the next call if it exists and insert null if it doesn’t.

Here is a very small example of data, I think all of the variations are covered.

use tempdb;
GO
CREATE TABLE dbo.product(mfg VARCHAR(32), part_number CHAR(5))

INSERT dbo.product SELECT 'mfg1','12345';
INSERT dbo.product SELECT 'mfg2','98765';
INSERT dbo.product SELECT 'mfg3','A1234';
INSERT dbo.product SELECT 'mfg4','5678A';

CREATE TABLE dbo.stock(mfg VARCHAR(32), part_number CHAR(5), onhand INT);

INSERT dbo.stock SELECT 'mfg1','12345',30;
INSERT dbo.stock SELECT 'mfg2','98765', 1;
INSERT dbo.stock SELECT 'mfg3','A1234', 9;
INSERT dbo.stock SELECT 'mfg4','5678A', 0;

CREATE TABLE dbo.calls(mfg VARCHAR(32), part_number CHAR(5), yyyymm CHAR(6));

INSERT dbo.calls SELECT 'mfg1','12345','201101';
INSERT dbo.calls SELECT 'mfg1','12345','201202';
INSERT dbo.calls SELECT 'mfg2','98765','201202';

Current result set:

mfg       part_number          last_call
mfg1      12345                 201101
mfg3      A1234                 NULL

What I want:

mfg        part_number         last_call
mfg1       12345               201101
mfg2       98765               NULL
mfg3       A1234               NULL
  • 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-30T12:39:14+00:00Added an answer on May 30, 2026 at 12:39 pm

    I think it just needs to be:

    SELECT p.mfg, p.part_number, last_call = max(c.yyyymm)
      FROM dbo.product AS p
      INNER JOIN dbo.stock AS s
        ON p.mfg = s.mfg AND p.part_number = s.part_number
      LEFT OUTER JOIN dbo.calls AS c
        ON p.mfg = c.mfg AND p.part_number = c.part_number
        AND c.yyyymm < '201202' -- only change
    WHERE s.onhand > 0;
    

    Why? Because moving an outer join criteria to the where clause converts the outer join to an inner join.

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

Sidebar

Related Questions

Using the following text as a sample, I need to be able to extract
What I need is to be able to extract the files in a .rar
I need to be able to extract jar files on the command line. Piece
I need to make a parser to be able to extract logical structure from
I need to be able to only extract the filename (info.txt) from a line
I'm using the Python email module to parse emails. I need to be able
I need to be able to extract a zip file, and insert the names
I need to be able to extract and transform data from a data source
Users of the website need to able to store images in their area ,
Need to be able to pull Magento products into an external template. Need to

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.