[Solved] SQL query for display one field only once which having multiple record


Using CASE Condition and Row_number we can achieve the above Output

It’s Purely based on your sample Data

DECLARE @Table1 TABLE 
    (projName varchar(1), percentage int)
;

INSERT INTO @Table1
    (projName, percentage)
VALUES
    ('A', 10),
    ('A', 25),
    ('B', 20),
    ('B', 30)
;

Select CASE WHEN RN = 1 THEN projName ELSE NULL END projName, percentage from (
select projName, percentage,ROW_NUMBER()OVER(PARTITION BY projName ORDER BY (SELECT NULL))RN from @Table1 )T

In your query I have modified the Answer

Select CASE WHEN T.RN = 1 THEN T.projName ELSE NULL END projName, T.percentage FROM  (select 
i.invoice_id,
pr.name as projname ,
ROW_NUMBER()OVER(PARTITION BY projName ORDER BY (SELECT NULL))RN
from annexure a,
project pr,
sow s,
invoice i 
where pr.project_id = s.project_id 
and a.sow_id = s.sow_id 
and i.annexure_id = a.annexure_id 
group by pr.name,i.invoice_date,i.invoice_id )T

4

solved SQL query for display one field only once which having multiple record