Friday, March 11, 2005

SQL Confusion.

Does this make sense to anybody:

declare @startdate datetime
declare @enddate datetime

select column1,
substring(column1,1,2),
substring(
column1,8,3),
substring(
column1,3,2),
substring(
column1,5,3),
end_datetime,
left(column2,3),
column3,
column4,
column5
from [SERVER].DB.dbo.table A
where status_code = 'c' and
end_datetime >= @startdate
and end_datetime <= @enddate
and end_datetime =
(select TOP 1 B.end_datetime
from [SERVER].DB.dbo.table B
where A.column1 = B.column1
and status_code = 'c'
and end_datetime >= @startdate
and end_datetime <= @enddate
order by end_datetime desc)

It's part of the stored procedure I'm using in the web project, coded by someone else. I'd like to comment it, but I have no idea what it does. Specifically, the bit at the end that starts with 'select TOP...'

Clues?

No comments: