Question: write in SQL server, Type the query below in a query window and run to see 2 table results IF OBJECT_ID('tempdb..#DestinationNetWorth') IS NOT NULL DROP

write in SQL server,

Type the query below in a query window and run to see 2 table results

IF OBJECT_ID('tempdb..#DestinationNetWorth') IS NOT NULL

DROP TABLE #DestinationNetWorth;

SELECT *

INTO #DestinationNetWorth

FROM

(

VALUES

(0, 25000),

(25001, 50000),

(50001, 200000),

(200001, 500000),

(500001, 1000000),

(1000001, 3000000),

(3000001, 100000000)

) AS a (MinRange, MaxRange);

IF OBJECT_ID('tempdb..#SourceNetworth') IS NOT NULL

DROP TABLE #SourceNetworth;

SELECT *

INTO #SourceNetworth

FROM

(

VALUES

('$25,000 and under'),

('$1,000,001 - $3,000,000'),

('$200,001 - $500,000'),

('$25000 - $50000'),

('$500,001 - $1,000,000'),

('$50,001 - $200,000'),

('$50,001-200,000'),

('$9,001-35,000')

) AS b (NetWorth);

SELECT * FROM #SourceNetworth

SELECT * FROM #DestinationNetWorth

Now write a select Query to get the results as below screenshot

NetWorth DestMin DestMax

----------------------- ----------- -----------

$25,000 and under 0 25000

$9,001-35,000 0 25000

$25000 - $50000 25001 50000

$50,001 - $200,000 50001 200000

$200,001 - $500,000 200001 500000

$500,001 - $1,000,000 500001 1000000

$1,000,001 - $3,000,000 1000001 3000000

Tips and Tricks

You need to join this table with the maximum overlapped range i.e if the expected ranges are 0-15;15- 30 and the given range is 10-25 you need to pick 15-30 as that is the maximum overlapped range

Youll may also need to do a lot of cast and converts to get it in the integer formats to compare the ranges

This can all be done in a single sql select statement if possible (recommend not to use Temp Tables)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!