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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:18:07+00:00 2026-05-30T22:18:07+00:00

A SQL question, probably not the most difficult. I’m making a view from a

  • 0

A SQL question, probably not the most difficult.

I’m making a view from a bunch of related table join on ID’s -> easy. Now there is one table that hasn’t got a key relationship with all the others. (BatchDates)

`ALTER VIEW [ECSUB].[FCT_Ext_Collection]
AS
SELECT     sh.id AS idSubmissionHistory, dh.id, dd.id AS Description, sch.id AS idScoringHistory, sh.CreationDate, sh.UpdateDate, bd.id AS BatchDateID
FROM         ECSUB.SubmissionHistory AS sh INNER JOIN EC.DocumentHistory AS dh ON sh.id = dh.idSubmissionHistory 
                      LEFT OUTER JOIN ECSM.ScoringHistory AS sch ON sh.idScoringHistory = sch.id 
                      LEFT OUTER JOIN EC.DocumentDescriptions AS dd ON dd.id = dh.Description 
                      LEFT OUTER JOIN ECSUB.AddressBilling AS ab ON sh.id = ab.id 
                      LEFT OUTER JOIN ECSUB.AddressPremise AS ap ON sh.id = ap.id 
                      CROSS JOIN EC.BatchDates AS bd --ON sh.documentdate between .......

GO`

Well, my main table ‘documentHistory’ contains a document date, I have to define in which batch this falls.
Each batch has an ID and startdate. A batch is always one month long.

This will make it much more easy to understand, the data from the BatchDates table:

id  month   startdate
1   2010-12-01 00:00:00.000 2010-12-01 00:00:00.000
1   2011-01-01 00:00:00.000 2010-12-01 00:00:00.000
1   2011-02-01 00:00:00.000 2010-12-01 00:00:00.000
2   2011-03-01 00:00:00.000 2011-03-01 00:00:00.000
2   2011-04-01 00:00:00.000 2011-03-01 00:00:00.000
2   2011-05-01 00:00:00.000 2011-03-01 00:00:00.000
3   2011-06-01 00:00:00.000 2011-06-01 00:00:00.000
3   2011-07-01 00:00:00.000 2011-06-01 00:00:00.000
3   2011-08-01 00:00:00.000 2011-06-01 00:00:00.000
4   2011-09-01 00:00:00.000 2011-09-01 00:00:00.000
4   2011-10-01 00:00:00.000 2011-09-01 00:00:00.000
4   2011-11-01 00:00:00.000 2011-09-01 00:00:00.000
5   2011-12-01 00:00:00.000 2011-12-01 00:00:00.000
5   2012-01-01 00:00:00.000 2011-12-01 00:00:00.000
5   2012-02-01 00:00:00.000 2011-12-01 00:00:00.000
6   2012-03-01 00:00:00.000 2012-03-01 00:00:00.000
6   2012-04-01 00:00:00.000 2012-03-01 00:00:00.000
6   2012-05-01 00:00:00.000 2012-03-01 00:00:00.000
7   2012-06-01 00:00:00.000 2012-06-01 00:00:00.000
7   2012-07-01 00:00:00.000 2012-06-01 00:00:00.000
7   2012-08-01 00:00:00.000 2012-06-01 00:00:00.000
8   2012-09-01 00:00:00.000 2012-09-01 00:00:00.000
8   2012-10-01 00:00:00.000 2012-09-01 00:00:00.000
8   2012-11-01 00:00:00.000 2012-09-01 00:00:00.000
9   2012-12-01 00:00:00.000 2012-12-01 00:00:00.000
9   2013-01-01 00:00:00.000 2012-12-01 00:00:00.000
9   2013-02-01 00:00:00.000 2012-12-01 00:00:00.000
10  2013-03-01 00:00:00.000 2013-03-01 00:00:00.000
10  2013-04-01 00:00:00.000 2013-03-01 00:00:00.000
10  2013-05-01 00:00:00.000 2013-03-01 00:00:00.000
etc...........

So I need to fetch the batchID based on the documentdate, therefore we use the currentMonth of the column startdate.

Thus: …JOIN BatchDates where documentDate is in startDate.month (there is no between here)

I don’t even know if I need a join, cross join, union, etc…

Thanks in advance!
L

  • 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-30T22:18:08+00:00Added an answer on May 30, 2026 at 10:18 pm
    join BatchDates 
    on datepart(yyyy,[document date]) = datepart(yyyy,[startDate])
    and datepart(mm,[document date]) = datepart(mm,[startDate])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to php and SQL so this is probably an easy question
I have a question about SQL Server indexes. I'm not a DBA and assume
I was inspired by the good answers from my previous question about SQL. Now
There is probably a simple answer to this question but I do not have
Sorry for the R101 question. I have a SQL Server 2008 table with a
This question was suggested by Kyralessa in the What is your most useful sql
My question specifically about sql-server, but probably can be answered by anyone with any
I have an SQL question which may be basic to some but is confusing
So I was thinking about creating a dynamic sql question, meaning that i want
T-SQL DateTime Question. I have a set of time ranges. During those time ranges

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.