question

askmlx121 avatar image
askmlx121 asked

Write a query to find ????

Hi I have a scenario like source table have below **Source table** **empid salary** 100 5000 101 4000 102 2000 and **Destionation table** **empid basic hra da** 100 2000 2000 1000 101 1000 500 500 102 1000 500 500 So source table empid and destination empid is have realation. **I want to check whether Source table salary column is equal to destionation table of basic+hra+da or not?** My output look like below: Empid Result 100 Equal 101 Not Equal 102 Equal **Can anyone help me to achive this in T-SQL?**
tsql
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Fatherjack avatar image
Fatherjack answered
USE [adventureworks] GO DECLARE @Source TABLE ( empid INT, salary INT ) INSERT @Source ( [empid], [salary] ) VALUES ( 100, 5000 ), ( 101, 4000 ), ( 102, 2000 ) DECLARE @Destination TABLE ( empid INT , BASIC INT , hra INT , da INT ) INSERT @Destination ( [empid], [BASIC], [hra], [da] ) VALUES ( 100, 2000, 2000, 1000 ), ( 101, 1000, 500, 500 ), ( 102, 1000, 500, 500 ) SELECT [d].[empid] , [d].[BASIC] , [d].[hra] , [d].[da] , CASE WHEN salary = [d].[BASIC] + hra + [d].[da] THEN 'Equal' ELSE 'Not Equal' END AS Comparison FROM @source AS s INNER JOIN @Destination AS d ON s.empid = d.empid
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

askmlx121 avatar image askmlx121 commented ·
hi jonathan allen thanking you. this is what i expected
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.