有人可以帮我吗-为什么这里的语法不正确?

时间:2019-09-11 08:40:33

标签: sql sql-server tsql

SELECT B.code + '-' + LEFT(F.code, 1) + '-' 
     + CAST(ROW_NUMBER() OVER (PARTITION BY AT.[description]  
                               ORDER BY ID) AS VARCHAR(10)) AS [code] 
     + '-' + AST.CODE,

我厌倦了()很少的选择,但没有用

SELECT B.code + '-' + LEFT(F.code, 1) + '-' 
       + CAST(ROW_NUMBER() OVER (PARTITION BY AT.[description] 
                                 ORDER BY ID) AS VARCHAR(10)) AS [code] 
       + '-' + AST.CODE,

1 个答案:

答案 0 :(得分:4)

您已将“ AS [code]”放在字符串操作内的错误位置。试试这个

SELECT B.code + '-' + 
    LEFT(F.code, 1) + '-' + 
    CAST(ROW_NUMBER() OVER (PARTITION BY AT.[description] ORDER BY ID) AS VARCHAR(10)) + 
    '-' + AST.CODE AS [code]