Click here to Skip to main content
15,894,460 members

compare two tables sql server 2005

itsureshuk asked:

Open original thread
Hi Frds I have three tables one is employee Detail,another is salary detail and other is salary given details..

Table 1:Employee Detail

Emp_Id Emp_Name
1 A
2 B
3 C
4 D
5 E
6 F
7 G
8 H
9 J
10 K


Table 2: Salary_Allocation
Emp_Id Salary_Month Salary_Amount
1 Jan 10000
2 Jan 9000
3 Jan 9000
4 Jan 9000
5 Jan 9000
6 Jan 9000
7 Jan 9000
8 Jan 8000
9 Jan 8500
10 Jan 8500
1 Feb 11000
2 Feb 10000
3 Feb 10000
4 Feb 10000
5 Feb 9500
6 Feb 9500
7 Feb 9500
8 Feb 8500
9 Feb 9000
10 Feb 8500


Table 3:Salary_Deposit

Emp_Id Salary_Month Salary_Deposit

1 Jan 10000
2 Jan 9000
3 Jan 7000
4 Jan 7000
5 Jan 7000
6 Jan 9000
7 Jan 7000
8 Jan 6000
9 Jan 6500
10 Jan 6500
1 Feb 9000
2 Feb 8000
3 Feb 8000
4 Feb 10000
5 Feb 7500
6 Feb 7500
7 Feb 9500
8 Feb 8500
9 Feb 7000
10 Feb 8500


by comparing above three tables ...I want to know which employee for which month how much salary is pending...


I need output as follows


Emp_Id Salary_Month Salary_Pending

3 Jan 2000
4 Jan 2000
5 Jan 2000
7 Jan 2000
8 Jan 2000
9 Jan 2000
10 Jan 2000
1 Feb 2000
2 Feb 2000
3 Feb 2000
5 Feb 2000
6 Feb 2000
9 Feb 2000
Tags: SQL Server 2005, SQL Server

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900