消息102 级别15 状态1 服务器,消息102,级别15,状态1'>'附近的语法不正确(Msg 102, Level 15, State 1 Incorrect syntax near '>')...

消息102,级别15,状态1'>'附近的语法不正确(Msg 102, Level 15, State 1 Incorrect syntax near '>')

我有一个像这样的SQL Server过程:

//Beginning of procedure

SELECT

CASE IDNumber

WHEN (DATALENGTH(IDNumber)>7)

THEN SUBSTRING(IDNumber,0,6)

WHEN (DATALENGTH(IDNumber) < 7)

THEN CONCAT((REPLICATE(0,7-LEN(IDNumber)),IDNumber)

END AS NID

//Rest of the procedure here

执行代码会在Incorrect syntax near '>'.引发错误Incorrect syntax near '>'.错误Incorrect syntax near '>'. 在线时WHEN (DATALENGTH(IDNumber)>7) 。

IDNumber是一个nvarchar 。 我尝试使用LEN(IDNumber)但徒劳无功。 我不知道错误是什么!

I have a SQL Server Procedure like this:

//Beginning of procedure

SELECT

CASE IDNumber

WHEN (DATALENGTH(IDNumber)>7)

THEN SUBSTRING(IDNumber,0,6)

WHEN (DATALENGTH(IDNumber) < 7)

THEN CONCAT((REPLICATE(0,7-LEN(IDNumber)),IDNumber)

END AS NID

//Rest of the procedure here

the code on execution throws the error Incorrect syntax near '>'. on line WHEN (DATALENGTH(IDNumber)>7) .

IDNumber is a nvarchar. I tried using LEN(IDNumber) but in vain. I don't know what the error is!

原文:https://stackoverflow.com/questions/39874629

更新时间:2020-10-14 14:10

最满意答案

像这样重写你的查询:

SELECT CASE

WHEN DATALENGTH(IDNumber) > 7 THEN SUBSTRING(IDNumber, 0, 6)

WHEN DATALENGTH(IDNumber) < 7 THEN CONCAT(REPLICATE(0, LEN(IDNumber)), IDNumber)

END AS NID;

编写CASE Column ,必须将其与直接值进行比较,而不是与表达式进行比较。

Rewrite your query like that:

SELECT CASE

WHEN DATALENGTH(IDNumber) > 7 THEN SUBSTRING(IDNumber, 0, 6)

WHEN DATALENGTH(IDNumber) < 7 THEN CONCAT(REPLICATE(0, LEN(IDNumber)), IDNumber)

END AS NID;

When you write CASE Column, you have to compare it to direct values, not to an expression.

相关问答

所有赋值操作必须以关键字set开头。 Set @TrID = @TrID + 1

正如Ivan指出的那样,你正在使用IsNull。 正确的用法是: If @TrID Is Null

All assignment operations must be preceded by the keyword set. Set @TrID = @TrID + 1

Also you are using IsNull incorrectly as Ivan points out. The proper usa

...

像这样重写你的查询: SELECT CASE

WHEN DATALENGTH(IDNumber) > 7 THEN SUBSTRING(IDNumber, 0, 6)

WHEN DATALENGTH(IDNumber) < 7 THEN CONCAT(REPLICATE(0, LEN(IDNumber)), IDNumber)

END AS NID;

编写CASE Column ,必须将其与直接值进行比较,而不是与表达式进行比较。 Rewrite you

...

with cte as

(

select *,

row_number() over ( partition by product order by date desc ) as rownumber

from saleslist

where datediff( month, [date], getdate() ) < 2

)

select product,

(

(max(case when rownumber = 1 then

...

@lastToken错过+ ' AND ' + @lastToken 和sp_executesql的@records参数提到了两次 @lastToken misses + ' AND ' + @lastToken and @records argument of sp_executesql two times mentioned

您只是在INSERT之前忘记了FOR (或AFTER )关键字: CREATE TRIGGER CLR_TRIGGER_NAUDOJASI

ON dbo.NAUDOJASI

FOR INSERT

AS

external name %Assembly.GeneratedName%.

go

在提出这样的问题之前,您应该首先在MSDN上查阅SQL Server联机丛书 ! 具有用于验证的任何T-SQL命令的精确语法 ! You simply forgot the FOR (or AFT

...

你应该用另一个报价来逃避单引号 试试这个: PRINT ''Date passed as a parameter -'' + CAST(@P_Date AS varchar(100))

编辑 顺便说一句,你应该在查询结束时放置一个END 完整代码: /****** Object: StoredProcedure [dbo].[MY_PROC] Script Date: 9/12/2013 3:31:17 PM ******/

IF EXISTS (SELECT * FROM sys.

...

在WITH之前加上一个分号(;)。 ;WITH Page_CTE AS (

正如错误信息告诉你的,前面的语句应该以分号结尾。 Put a semicolon (;) just before WITH. ;WITH Page_CTE AS (

As the error message tells you, the previous statement should be terminated with a semicolon.

对于OP的命令: select compid,2, convert(datetime, '01/01/' + CONVERT(char(4),cal_yr) ,101) ,0, Update_dt, th1, th2, th3_pc , Update_id, Update_dt,1

from #tmp_CTF**

我得到这个错误: Msg 102, Level 15, State 1, Line 2

Incorrect syntax near '*'.

当调试像这样的东西时,将长排队分开

...

这是你的问题 insert into Configuration..ngap2

values ('@code1',

'select top 1 Description_acte from Configuration..ngap where Code='@code1' order by 'Code'',

'select top 1 Lettre from Configuration..ngap where Code='@code1' order by 'Cod

...

使用表别名尝试下面的一个 select @startDT,@endDT,timeDiff,CaseType,QueueType,count(id_queue)

from

(

SELECT (CASE

WHEN DATEPART(hour, dt_created_by) = '0' THEN '00 - 01'

WHEN DATEPART(hour, dt_created_by) = '1' THE

...

参与评论 您还未登录,请先 登录 后发表或查看评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:深蓝海洋 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值