Hi @hafifiw,
Please refer to the below query.
-Under 'TankDetails' 'ID' Datatype is int then try
CREATE TABLE #TankLine(Tank INT, Line VARCHAR(20),Type varchar(20))
INSERT INTO #TankLine VALUES(1, '1A','CNT_A')
INSERT INTO #TankLine VALUES(1, '1B','CNT_A')
INSERT INTO #TankLine VALUES(1, '1C','CNT_A')
INSERT INTO #TankLine VALUES(2, '2Q','CNT_A')
INSERT INTO #TankLine VALUES(2, '2W','CNT_A')
INSERT INTO #TankLine VALUES(2, '2E','CNT_A')
INSERT INTO #TankLine VALUES(3, '3R','CNT_A')
INSERT INTO #TankLine VALUES(3, '3T','CNT_A')
INSERT INTO #TankLine VALUES(3, '3I','CNT_A')
INSERT INTO #TankLine VALUES(3, '3P','CNT_A')
Create Table #TankDetails(Tank INT, Line VARCHAR(20),Type varchar(20),ID int)
INSERT INTO #TankDetails VALUES(1, '1A','CNT_A',331)
INSERT INTO #TankDetails VALUES(1, '1B','CNT_A',311)
INSERT INTO #TankDetails VALUES(2, '2Q','CNT_A',122)
INSERT INTO #TankDetails VALUES(3, '3T','CNT_A',121)
INSERT INTO #TankDetails VALUES(3, '3I','CNT_A',144)
INSERT INTO #TankDetails VALUES(3, '3P','CNT_A',145)
Create Table #TankRemark (ID int,Remark char(1))
INSERT INTO #TankRemark VALUES(331,'Y')
INSERT INTO #TankRemark VALUES(311, 'Y')
INSERT INTO #TankRemark VALUES(122, 'Y')
INSERT INTO #TankRemark VALUES(121, 'Y')
INSERT INTO #TankRemark VALUES(144, 'Y')
INSERT INTO #TankRemark VALUES(145, 'Y')
SELECT L.Tank,L.Line,L.Type,D.ID,
CASE WHEN D.ID IS NULL THEN '-' ELSE R.Remark End As Remark
FROM #TankLine L LEFT JOIN
#TankDetails D ON L.Line=d.Line LEFT JOIN
#TankRemark R ON D.ID=r.ID
-Under 'TankDetails' 'ID' Datatype is nvarchar then try
CREATE TABLE #TankLine(Tank INT, Line VARCHAR(20),Type varchar(20))
INSERT INTO #TankLine VALUES(1, '1A','CNT_A')
INSERT INTO #TankLine VALUES(1, '1B','CNT_A')
INSERT INTO #TankLine VALUES(1, '1C','CNT_A')
INSERT INTO #TankLine VALUES(2, '2Q','CNT_A')
INSERT INTO #TankLine VALUES(2, '2W','CNT_A')
INSERT INTO #TankLine VALUES(2, '2E','CNT_A')
INSERT INTO #TankLine VALUES(3, '3R','CNT_A')
INSERT INTO #TankLine VALUES(3, '3T','CNT_A')
INSERT INTO #TankLine VALUES(3, '3I','CNT_A')
INSERT INTO #TankLine VALUES(3, '3P','CNT_A')
Create Table #TankDetails(Tank INT, Line VARCHAR(20),Type varchar(20),ID nvarchar(10))
INSERT INTO #TankDetails VALUES(1, '1A','CNT_A',331)
INSERT INTO #TankDetails VALUES(1, '1B','CNT_A',311)
INSERT INTO #TankDetails VALUES(2, '2Q','CNT_A',122)
INSERT INTO #TankDetails VALUES(3, '3T','CNT_A',121)
INSERT INTO #TankDetails VALUES(3, '3I','CNT_A',144)
INSERT INTO #TankDetails VALUES(3, '3P','CNT_A',145)
Create Table #TankRemark (ID nvarchar(10),Remark char(1))
INSERT INTO #TankRemark VALUES(331,'Y')
INSERT INTO #TankRemark VALUES(311, 'Y')
INSERT INTO #TankRemark VALUES(122, 'Y')
INSERT INTO #TankRemark VALUES(121, 'Y')
INSERT INTO #TankRemark VALUES(144, 'Y')
INSERT INTO #TankRemark VALUES(145, 'Y')
SELECT L.Tank,L.Line,L.Type,
CASE WHEN D.ID IS NULL THEN '-' ELSE D.ID End As ID,
CASE WHEN D.ID IS NULL THEN '-' ELSE R.Remark End As Remark
FROM #TankLine L LEFT JOIN
#TankDetails D ON L.Line=d.Line LEFT JOIN
#TankRemark R ON D.ID=r.ID