Click here to Skip to main content
15,888,069 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
plz help me I stake here. currenly I am working in sql -2000.
and My table like this :-

CSS
PerformanceDate	  Score	  Category Reason	UserName	Event_Date
-----------------------------------------------------------------------------------
2009-07-14 11:20    0   	L2  MVR     	System  	2009-07-14 11:20
2009-07-14 11:20    0   	L2  MVR     	System  	2009-07-14 11:20
2009-07-14 11:20    0   	L2  Collision   System  	2009-07-14 11:20
2009-07-14 11:20    4   	L2  MVR     	System  	2009-07-14 11:20
2009-07-14 11:20    0   	L2  MVR     	System  	2009-07-14 11:20
2009-07-14 11:20    0   	L2  Collision   System  	2009-07-14 11:20
2009-07-14 11:20    0   	L2  Collision   System  	2009-07-14 11:20
2009-07-14 11:20    0   	L2  MVR     	System  	2009-07-14 11:20
2009-07-14 11:20    0   	L2  MVR     	System  	2009-07-14 11:20


AND I NEED A OUTPUT LIKE THIS.


XML
<pre lang="css">

PerformanceDate   Score   Category Reason   UserName    Event_Date
-----------------------------------------------------------------------------------
2009-07-14 11:20    0       L2  MVR         System      2009-07-14 11:20
2009-07-14 11:20    0       L2  Collision   System      2009-07-14 11:20
2009-07-14 11:20    4       L2  MVR         System      2009-07-14 11:20
2009-07-14 11:20    0       L2  MVR         System      2009-07-14 11:20
2009-07-14 11:20    0       L2  Collision   System      2009-07-14 11:20
2009-07-14 11:20    0       L2  MVR         System      2009-07-14 11:20
</pre>


NOTE : if previous rows data and current rows data both are same then eliminate the current data.
Posted

Use the DISTINCT keyword, and SQL Server won't return duplicate data.

select DISTINCT (....

Oh, you want it a little more complex than that. I would think you may need to use a cursor to do this.
 
Share this answer
 
v2
Try this.

For Sql Server 2000
XML
SELECT IDENTITY(int,1,1)  AS row_num,PerformanceDate, Score ,Category ,Reason ,UserName,Event_Date
 into #temptable
  FROM tbl_Temp

SELECT
    [current].PerformanceDate,[current].Score ,[current].Category ,[current].Reason ,[current].UserName,[current].Event_Date,row_num
FROM
    #temptable AS [current]
LEFT OUTER JOIN
    #temptable AS previous
    ON [current].PerformanceDate = previous.PerformanceDate
    AND [current].Score = previous.Score
    AND [current].Category = previous.Category
    AND [current].Reason = previous.Reason
    AND [current].UserName = previous.UserName
      AND [current].Event_Date = previous.Event_Date
    AND [current].row_num = previous.row_num + 1
WHERE
    [current].PerformanceDate = previous.PerformanceDate
    AND [current].Score <> previous.Score
    AND [current].Category <>previous.Category
    AND [current].Reason <> previous.Reason
    AND [current].UserName <>previous.UserName
      AND [current].Event_Date <>previous.Event_Date
ORDER BY
    [current].PerformanceDate
 
Share this answer
 
XML
WITH CTE_TEST AS
(
    SELECT PerformanceDate, Score ,Category ,Reason ,UserName,Event_Date,
           ROW_NUMBER() OVER (PARTITION BY PerformanceDate, Score ,Category ,Reason ,UserName,Event_Date ORDER BY PerformanceDate) AS row_num
    FROM tbl_Temp
)
SELECT
    [current].PerformanceDate,[current].Score ,[current].Category ,[current].Reason ,[current].UserName,[current].Event_Date,
FROM
    CTE_TEST AS [current]
LEFT OUTER JOIN
    CTE_TEST AS previous
    ON [current].PerformanceDate = previous.PerformanceDate
    AND [current].Score = previous.Score
    AND [current].Category = previous.Category
    AND [current].Reason = previous.Reason
    AND [current].UserName = previous.UserName
      AND [current].Event_Date = previous.Event_Date
    AND [current].row_num = previous.row_num + 1
WHERE
    [current].PerformanceDate = previous.PerformanceDate
    AND [current].Score <> previous.Score
    AND [current].Category <>previous.Category
    AND [current].Reason <> previous.Reason
    AND [current].UserName <>previous.UserName
      AND [current].Event_Date <>previous.Event_Date
ORDER BY
    [current].PerformanceDate



I have tested it with my table. Its working fin. If it didnt work, send me your table script, i will help you
 
Share this answer
 
Comments
P.S Vijay 2-Aug-12 5:09am    
Hi Santhosh Kumar

I am Vijay, Good work but dear I working in SQL 2000, ROW_NUMBER/PARTITION ect is not there. rest is the table structure keep it as it is no problem for that.



Thanks & regards
Vijay
Santhosh Kumar Jayaraman 2-Aug-12 6:59am    
I have posted another solution compatible for Sqlserver 2000

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900