开发者

Sorting the date column incorrectly in SSRS

开发者 https://www.devze.com 2023-03-30 18:38 出处:网络
I have a stored procedure to generate report using the SQL Server Reporting Services. Stored Procedure returns results and has one date column.

I have a stored procedure to generate report using the SQL Server Reporting Services. Stored Procedure returns results and has one date column.

Now i would like to display the date in Aug 5 20开发者_如何学编程09, 11:20:AM format instead of showing MM/DD/YYYY so i have cast the date as follows in select query inside the Stored Procedure [select col1, col2, cast(datecol as varchar(max) ...)]. This has helped me get the date displayed in correct format i wanted but the columns are getting sort as per text(A-Z) instead of the date.

Can someone tell me what should i do so that i am able to get the date in expected format and still be able to sort the column like its Date not String?


Send the data as a date, and use reporting services Format method to change the way it is displayed.

See this thread for description of the parameters to use

So you'll end up using something like this expression:

=Format(Fields!MyDateField,"MMM d yyyy, HH:mm tt")


=CDate(Fields!MyDateField.Value)

The value returned in your report are a "String", CDate converts this string value to a Date type. Doing that possible the sort by this column as Date type correctly.

0

精彩评论

暂无评论...
验证码 换一张
取 消