Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,558 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Below sql print which data has duplicate but i want the output bit different way
I want to print the actual data and duplicate too. in the below sql here data is group by masterid,SectionID, LineItemID,PeriodID but their value field could have different data.
so tell me how could i print actual & duplicate too in same result one after one. if my question not clear then please let me know so i will try to elaborate it with example. thanks
WITH CTE AS
(
SELECT *,ROW_NUMBER() OVER (PARTITION BY masterid,SectionID, LineItemID,PeriodID ORDER BY masterid,SectionID, LineItemID,PeriodID) AS RN
FROM tblTicker_Bogey
)
Select * from CTE where RN>1
Try this query:
SELECT *
FROM tblTicker_Bogey
ORDER BY masterid,SectionID, LineItemID,PeriodID
If I understand it correctly, this is what you're after:
WITH CTE AS (
SELECT *, COUNT() OVER (PARTITION BY masterid,SectionID, LineItemID,PeriodID) AS cnt
FROM tblTicker_Bogey
)
Select * from CTE where cnt>1