Reporting Services 2005 - 条件日期格式不起作用

发布于 2024-10-05 04:37:12 字数 497 浏览 1 评论 0原文

...所以我的 sql 视图将 nvarchar 返回为“123456”或“JAN 11 2008 12:00AM”(视图对两个表进行并集并将日期转换为 nvarchar)。

我正在尝试应用一些条件日期格式,即我想通过检查“类型”列来格式化日期:

=IIf(Fields!Type.Value = "COS", Fields!CosNoOrDateToContractor.Value, FormatDateTime  (Fields!CosNoOrDateToContractor.Value, vbShortDate))

所以基本上,如果类型是“COS”,则只需按原样返回数据,否则将其格式化为日期。

预览报告时,如果它是 COS,则我在文本框中收到 #Error(从字符串“123456”转换为类型“日期”无效。

它是其他数据,然后数据格式化为日期。

这有意义吗?

有什么问题吗 还是我想要做的不可能?

?语法

...so my sql view returns nvarchar as '123456' or 'JAN 11 2008 12:00AM' (view does a union on two tables and casts date to nvarchar).

I'm trying to apply some conditional date formatting i.e. I want to format the date by checking the "Type" column as:

=IIf(Fields!Type.Value = "COS", Fields!CosNoOrDateToContractor.Value, FormatDateTime  (Fields!CosNoOrDateToContractor.Value, vbShortDate))

So basically if the type is a "COS" then just return the data as is, otherwise format it to a date.

When previewing the report if its a COS then I get #Error in the textbox (Conversion from string "123456" to type 'Date' is not valid.

It's anything else then data is formatted as date.

Does this make sense?

Anything wrong with the syntax or is what I'm trying to do not possible?

alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌若浮生 2024-10-12 04:37:12

我的猜测是,您在文本框“格式”字段中有一些格式,

否则,当您期望日期时,您会得到一个数字。

尝试添加 IsDate() 检查以删除非日期

=IIf(Fields!Type.Value <> "COS" AND IsDate(Fields!CosNoOrDateToContractor.Value)
     , FormatDateTime (Fields!CosNoOrDateToContractor.Value, vbShortDate)
      , Fields!CosNoOrDateToContractor.Value)

编辑:

在数据集中,它表示什么数据类型?

My guess is that you have some formatting in the text box "Format" field

Otherwise, you have a number when you expect a date.

Try adding an IsDate() check too to remove non-date

=IIf(Fields!Type.Value <> "COS" AND IsDate(Fields!CosNoOrDateToContractor.Value)
     , FormatDateTime (Fields!CosNoOrDateToContractor.Value, vbShortDate)
      , Fields!CosNoOrDateToContractor.Value)

Edit:

In the DataSet, what datatype does it say please?

很酷不放纵 2024-10-12 04:37:12

已修改视图,因此我不会将日期转换为 nvarchar。

Have modified the view instead so I'm not casting dates to nvarchar.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文