gpt4 book ai didi

sql-server - SQL Server 2008 R2 bug 还是什么?

转载 作者:行者123 更新时间:2023-12-02 14:48:30 25 4
gpt4 key购买 nike

我观察到一种奇怪的行为。以下与将 nvarchar 子字符串转换为 tinyint 相关的代码工作正常:

DECLARE @s nvarchar(50) = N'Line 1'
DECLARE @n tinyint = SUBSTRING(@s, 6, 10)

SELECT
N'Line 1' AS explicit_nvarchar,
@s AS nvarchar_variable,
SUBSTRING(@s, 6, 10) AS nvarchar_substring
, @n AS tinyint_var_converted_earlier
, CAST(SUBSTRING(@s, 6, 10) AS tinyint) AS cast_sub_var
, CAST(SUBSTRING(N'Line 1', 6, 10) AS tinyint) AS cast_nvarchar_substr

我可以在 Microsoft SQL Server Management Studio 中观察到以下输出:

enter image description here

但是,如果注释行未注释,则尝试处理表中的 SELECT 的代码将失败:

Select 
[order].[identifier] As [order_identifier],
[plan_data].[starts_on] As [from],
[plan_data].[ends_on] As [to],
[workplace].[identifier] AS line_identifier,
SUBSTRING([workplace].[identifier], 6, 10) AS line_no_str
--, CAST(SUBSTRING([workplace].[identifier], 6, 10) AS int) AS line_no
From
...

带有注释行... enter image description here

但未注释行(均用于转换为 tinyintint)...

enter image description here

更新:奇怪。我已将最后一行添加到 WHERE 以检查所有行是否包含'Line...

Where
[plan].[identifier] = @lPlanIdentifier And
(
[plan_data].[starts_on] Between @fromUTC And @toUTC Or
[plan_data].[ends_on] Between @fromUTC And @toUTC)
AND LEFT([workplace].[identifier], 4) = N'Line'

...突然间它也适用于未注释的行。我怎样才能找出导致问题的原因?

更新2:我应该遵循Hamlet Hakobyan's answer与发布时完全相同。当查看表格内部时,我可以看到:

enter image description here

最佳答案

identifier 列中有值,SUBSTRING([workplace].[identifier], 6, 10) 返回 ined

尝试这个查询:

SELECT * FROM [workplace]
WHERE SUBSTRING([identifier], 6, 10) = N'ined'

关于sql-server - SQL Server 2008 R2 bug 还是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14468588/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com