...所以我的 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?
发布评论
评论(2)
我的猜测是,您在文本框“格式”字段中有一些格式,
否则,当您期望日期时,您会得到一个数字。
尝试添加 IsDate() 检查以删除非日期
编辑:
在数据集中,它表示什么数据类型?
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
Edit:
In the DataSet, what datatype does it say please?
已修改视图,因此我不会将日期转换为 nvarchar。
Have modified the view instead so I'm not casting dates to nvarchar.