I have Table in which We can have Same ticket no.for multiple entries.i want to retrieve most recent ticket(of same ticket no.) number based on Initiated on column.
Ticket VendorTicket InitiatedOn Comments
198165 test 2012-08-10 16:31:33.707 test
199485 sagar 2012-08-11 12:36:25.720 sagar
199485 sagar1 2012-08-11 14:36:25.720 sagar1
199478 kishor 2012-08-11 12:37:21.923 kishor
I have Written this query in T-SQL in Stored Procedure It gives me Error Saying xObj = {"Incorrect syntax near '.'."}
My T-SQL
`@SQL='Select ''<a href="javascript:editTicketByIDAction('' + CONVERT(VarChar(Max), Ticket) + '')">'' + CONVERT(VarChar(Max),Ticket) + ''</a>'' t1.Ticket,t1.VendorTicket[Vendor Ticket],t1.Comments
From VendorTickets t1
WHERE NotifyOn <= GetDate() And NotifyOn Is Not Null AND
NOT EXISTS
(SELECT * FROM VendorTickets t2
WHERE t1.Ticket = t2.Ticket AND t1.InitiatedOn < t2.InitiatedOn)'`
A general solution (works on any database) to this problem is the following:
This reads: Get all value from my_table where there is no ticket with the same
TicketID and a more recent date.Notes:
InitiatedOnvalue.TicketandInitiatedOncolumns