This query is run on AdventureWorks2014.Sales.SalesOrderDetail table.
My query: in the CASE clause I have clearly stated to show - when it is the ELSE case. This query removes the repeating SalesOrderID and after 1st time shown it should be replaced with "-" this character.
SELECT
CASE WHEN ROW_NUMBER() OVER(PARTITION BY SalesOrderID ORDER BY SalesOrderID ASC) = 1 THEN SalesOrderID ELSE '-' END AS SalesOrderID,
R.ProductID,
R.OrderQty,
R.UnitPrice,
R.LineTotal
FROM AdventureWorks2014.Sales.SalesOrderDetail AS R
currently showing 0 even though i said in the ELSE to show me -

Below query will solve your issue
SELECT
CASE WHEN ROW_NUMBER() OVER(PARTITION BY SalesOrderID ORDER BY SalesOrderID ASC) = 1 THEN CONVERT(varchar(10),SalesOrderID) ELSE '-' END AS SalesOrderID,
R.ProductID,
R.OrderQty,
R.UnitPrice,
R.LineTotal
FROM AdventureWorks2014.Sales.SalesOrderDetail AS R
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With