“cast”附近的语法不正确;
不明白为什么我会收到错误
substring(cast(CASE WHEN l.assigned IS NOT NULL THEN l.分配的 ELSE l2.指定 END), 0, 17) 作为 [TEST1]
更新:
我试图调整的原始行如下...想要取出该转换,因为我不希望日期时间采用这种格式:
,否则子字符串(转换(varchar, 强制转换(当 l.assigned 不为空时的情况 THEN l. 已分配 ELSE l2. 已分配 END 作为日期时间), 126), 0, 17) 结束) 作为 varchar(20)) 作为 [TEST1]
我也尝试了这个,但我忘了提及
substring(cast(CASE WHEN l.assigned IS NOT NULL THEN l.分配的 ELSE l2.指定为日期时间 END), 0, 17) 作为[测试1]
错误:关键字“as”附近的语法不正确。
Can't figure out why I get the error
substring(cast(CASE WHEN l.assigned IS
NOT NULL THEN l.assigned ELSE
l2.assigned END), 0, 17) as [TEST1]
UPDATED:
The original line I was trying to tweak is the following...wanted to take out that convert because I don't want that format for the datetime:
, else substring(convert(varchar,
cast(CASE WHEN l.assigned IS NOT NULL
THEN l.assigned ELSE l2.assigned END
as datetime), 126), 0, 17) end) as
varchar(20)) as [TEST1]
Also I tried this which I forgot to mention
substring(cast(CASE WHEN l.assigned IS
NOT NULL THEN l.assigned ELSE
l2.assigned as datetime END), 0, 17)
as [TEST1]
Error: Incorrect syntax near the keyword 'as'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您收到错误是因为您没有按此处。语法如下:
您可以使用 isnull(或合并)和左。请记住,除非您正在寻找特定的日期时间格式,否则您只需执行以下操作:
You get an error because you didn't specify a data-type as detailed here. The syntax goes something like this:
You can more simply express your query using isnull (or coalesce) and left. Keep in mind that unless you're looking for a specific datetime format, you can just do the following:
CAST
需要似乎缺少的AS 数据类型
。例如,
您还可以使用
ISNULL
或COALESCE
来稍微缩短代码。CAST
needs anAS datatype
that appears to be missing.e.g.
You can also use
ISNULL
orCOALESCE
to shorten your code a bit.您要转换为什么数据类型?请参阅参考:
http://msdn.microsoft.com/en-us/library/ ms187928.aspx
您缺少“as”子句和数据类型。
To what data type you are casting? See reference:
http://msdn.microsoft.com/en-us/library/ms187928.aspx
You are missing 'as' clause and data type.
您需要将其转换为类型。
msdn:CAST 和 CONVERT
You need to cast it to a type.
msdn: CAST and CONVERT