“cast”附近的语法不正确;

发布于 2024-11-09 13:50:18 字数 577 浏览 0 评论 0原文

不明白为什么我会收到错误

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 技术交流群。

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

发布评论

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

评论(4

時窥 2024-11-16 13:50:18

您收到错误是因为您没有按此处。语法如下:

select cast('1/1/1911' as datetime)

您可以使用 isnull(或合并)和。请记住,除非您正在寻找特定的日期时间格式,否则您只需执行以下操作:

select left(isnull(l.assigned,l2.assigned),17) as [TEST1]

You get an error because you didn't specify a data-type as detailed here. The syntax goes something like this:

select cast('1/1/1911' as datetime)

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:

select left(isnull(l.assigned,l2.assigned),17) as [TEST1]
通知家属抬走 2024-11-16 13:50:18

CAST 需要似乎缺少的 AS 数据类型

例如,

SELECT SUBSTRING(CAST(
         CASE WHEN 'foo' IS NOT NULL THEN 'foo' ELSE 'FOO' END AS VARCHAR(100))
       , 0, 17) AS [TEST1]

您还可以使用 ISNULLCOALESCE 来稍微缩短代码。

SELECT SUBSTRING(CAST(COALESCE(l.assigned,l2.assigned) AS VARCHAR(100)), 0, 17) 
                                                                       AS [TEST1]

CAST needs an AS datatype that appears to be missing.

e.g.

SELECT SUBSTRING(CAST(
         CASE WHEN 'foo' IS NOT NULL THEN 'foo' ELSE 'FOO' END AS VARCHAR(100))
       , 0, 17) AS [TEST1]

You can also use ISNULL or COALESCE to shorten your code a bit.

SELECT SUBSTRING(CAST(COALESCE(l.assigned,l2.assigned) AS VARCHAR(100)), 0, 17) 
                                                                       AS [TEST1]
赏烟花じ飞满天 2024-11-16 13:50:18

您要转换为什么数据类型?请参阅参考:

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.

避讳 2024-11-16 13:50:18

您需要将其转换为类型。

msdn:CAST 和 CONVERT

You need to cast it to a type.

msdn: CAST and CONVERT

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