|
hmusa
Starting Member
36 Posts |
Posted - 2001-08-29 : 07:20:25
|
| I have the following query that sorts out news stories by date and time it is correctly sorting by date but the times are not, it seems that the order by time clause is not workingAny Ideas?Thanxs in advance DROP PROC spNewsTEST goCREATE PROC spNewsTEST @PPNT VARCHAR(2)='NT', @ID VARCHAR(6)= '%', @SearchText VARCHAR(255) = ''as BEGINDECLARE @DateFilter DATETIME-- @PPNT is a filter on the source of the data-- we need a date filter when no ID is passed. We can give each date range a code.-- DateRangeCode 1 - today-- DateRangeCode 2 - Last week-- DateRangeCode 3 - Last monthSELECT @DateFilter = '01 jan 1900'if @ID = '%' BEGIN SELECT @DateFilter = DATEadd(m,-1 ,GETDATE() )ENDIF @SearchText = ''BEGIN select sourceCode, CONVERT(VARCHAR(11),CONVERT(smallDATETIME,[date],103) ) as Date,LTRIM(substring(convert(VARCHAR(25),[time]),13,7)) as time, id,headline,NewsID, CASE WHEN DATEDIFF(dd, date,GETDATE() ) <1 THEN 1 WHEN DATEDIFF(dd, date,GETDATE() ) BETWEEN 1 AND 7 THEN 2 WHEN DATEDIFF(dd, date,GETDATE() ) BETWEEN 8 AND 31 THEN 3 ELSE 4 END as DateRangeCode, Pending, Announcement, LastModifiedDate,LastmodifiedUser from news (NOLOCK) where id like @ID AND SourceCode = @PPNT AND Date >= @DateFilter ORDER BY dateRangeCode, convert(datetime,[date]) desc,[time] DESCEND-- for search text use this queryIF @SearchText <> ''BEGIN select sourceCode, CONVERT(VARCHAR(11),CONVERT(smallDATETIME,[date],103) ) as Date,LTRIM(substring(convert(VARCHAR(25),[time]),13,7)) as time, id,headline,NewsID, CASE WHEN DATEDIFF(dd, date,GETDATE() ) <1 THEN 1 WHEN DATEDIFF(dd, date,GETDATE() ) BETWEEN 1 AND 7 THEN 2 WHEN DATEDIFF(dd, date,GETDATE() ) BETWEEN 8 AND 31 THEN 3 ELSE 4 END as DateRangeCode, Pending, Announcement, LastModifiedDate,LastmodifiedUser from news (NOLOCK) where id like @ID AND SourceCode = @PPNT AND ( story like '%' + @SearchText + '%' OR headline like '%' + @SearchText + '%' OR firstline like '%' + @SearchText + '%' ) AND Date >= @DateFilter order by convert(datetime,[date]) desc,[time] descENDENDgoEdited by - hmusa on 08/29/2001 07:37:49 |
|