Solved

Merge fields from two tables in a view based on a span of days

Posted on 2015-01-08
2
51 Views
Last Modified: 2015-01-08
I have two tables;  PayData  with 5 fields:  PRDate, Dept, Amount, Hours, EarnCode and PaySched with 5 fields; PRNum, FromDate, ThroughDate, RptDate, Year.  


I want to merge the field values within the PayData file with the correct PRNum when the PayData.PRDate falls within the PaySched.FromDate and PaySched.ThroughDate.


How can I define the view to get what I need?

Thanks

Glen
0
Comment
Question by:GPSPOW
2 Comments
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 500 total points
ID: 40539123
--CREATE VIEW [view_name] AS
SELECT pd.*, ps.* --whatever columns you need from each table
FROM PayData pd
LEFT OUTER JOIN PaySched ps ON
    pd.PRDate >= ps.FromDate AND
    pd.PRDate <= ps.ThroughDate
0
 

Author Closing Comment

by:GPSPOW
ID: 40539178
Thank you
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
T-SQL: "HAVING CASE" Clause 1 27
Query group by data in SQL Server - cursor? 3 34
SSRS Enable Remote Errors 4 26
SQL Query Help Top 1 and Distinct? 6 26
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question