can anyone please help: I tried to join with duplicate values but it is not coming as I wanted.
CREATE TABLE #TestTable1 ([No] varchar(50),[Value1] float,[Desc] varchar(50))
insert into #TestTable1 ([No],[Value1],[Desc])
Values
(N'123953',427.2,N'Basic Hours')
,(N'123953',106.8,N'Basic Hours')
,(N'123953',213.6,N'Basic Hours')
,(N'123953',213.6,N'Basic Hours')
,(N'123953',213.6,N'Basic Hours')
,(N'123953',213.6,N'Basic Hours')
,(N'123953',105.6,N'Basic Hours')
CREATE TABLE #TestTable2 ([No] varchar(50),[Value2] float,[Desc] varchar(50))
insert into #TestTable2 ([No],[Value2],[Desc])
Values
(N'123953',553.02,N'Basic Hours')
,(N'123953',446.67,N'Basic Hours')
,(N'123953',427.2,N'Basic Hours')
,(N'123953',106.8,N'Basic Hours')
,(N'123953',213.6,N'Basic Hours')
,(N'123953',213.6,N'Basic Hours')
,(N'123953',213.6,N'Basic Hours')
,(N'123953',105.6,N'Basic Hours')
Desired Output:
[No],[Desc],[Value1],[Value2]
(N'123953',N'Basic Hours',427.2,427.2)
,(N'123953',N'Basic Hours',106.8,106.8)
,(N'123953',N'Basic Hours',213.6,213.6)
,(N'123953',N'Basic Hours',213.6,213.6)
,(N'123953',N'Basic Hours',213.6,213.6)
,(N'123953',N'Basic Hours',213.6,NULL)
,(N'123953',N'Basic Hours',105.6,105.6)
Note: I can't join on Value field for other reasons.
I tried to use row_number()
but still not coming as my desired output.
Thanks in advance.