SQL As附近的语法错误

时间:2017-12-27 05:35:51

标签: sql-server tsql

我找不到导致语法的问题。它有点长而且头晕。它给出了

  

“语法不正确”

在底部脚本上,我无法找到它的原因。完成输出将只有一列,其上有一个很长的长字符串。 希望一组新的眼睛可以帮助我。感谢

        Select 'TUEF'+'11'+(RTRIM(APPMNBR) + SPACE(25 - LEN(APPMNBR)))+
         (RTRIM('') + SPACE(10 - LEN('')))+SPACE(8)+'1000'+'A'+
         ('000010000' + SPACE(9 - LEN('000010000')))+'PHP'+
        'EN'+'08'+'TT'+'009'+'000000'+'NA03N01'
        +'01'+
        CASE when LEN(LTRIM(RTRIM(APPMFSTNM))) <= 9 
        then '0'+ LEN(LTRIM(RTRIM(APPMFSTNM)))
        else  LEN(LTRIM(RTRIM(APPMFSTNM)))
        end +(LTRIM(RTRIM(LEFT(APPMFSTNM,30))))


        +'02'+
        CASE when LEN(LTRIM(RTRIM(APPMMDLNM))) <= 9 
        then '0'+ LEN(LTRIM(RTRIM(APPMMDLNM)))
        else  LEN(LTRIM(RTRIM(APPMMDLNM)))
        end +(LTRIM(RTRIM(LEFT(APPMMDLNM,30)))


        +'03'+
        CASE when LEN(LTRIM(RTRIM(APPMLSTNM))) <= 9 
        then '0'+ LEN(LTRIM(RTRIM(APPMLSTNM)))
        else  LEN(LTRIM(RTRIM(APPMLSTNM)))
        end
         +(LTRIM(RTRIM(LEFT(APPMLSTNM,30))))

        +'04'+
        CASE when LEN(LTRIM(RTRIM(APPMMOM))) <= 9 
        then '0'+ LEN(LTRIM(RTRIM(APPMMOM)))
        else  LEN(LTRIM(RTRIM(APPMMOM)))
        end
        +(LTRIM(RTRIM(LEFT(APPMLSTNM,40))))

        +'0608'+
         +(LTRIM(RTRIM(RIGHT(APPMDOB,2))))+
         +(LTRIM(RTRIM(SUBSTRING(APPMDOB,5,2))))+
         +(LTRIM(RTRIM(LEFT(APPMDOB,4))))+

        +'ID03I01'+
         Case when APPMTIN <>'' then
                CASE when LEN(LTRIM(RTRIM(APPMTIN))) <= 9 
                then '0'+ LEN(LTRIM(RTRIM(APPMTIN)))
                else  LEN(LTRIM(RTRIM(APPMTIN))) 
                end 


              when APPMTIN = '' and APPMSSS <> ''  then 
                CASE when LEN(LTRIM(RTRIM(APPMSSS))) <= 9 
                then '0'+ LEN(LTRIM(RTRIM(APPMSSS)))
                else  LEN(LTRIM(RTRIM(APPMSSS)))
                end 
              end


        + Case when APPMTIN <>'' then (LTRIM(RTRIM(LEFT(APPMTIN,50)))) 
              when APPMTIN = '' and APPMSSS <> ''  then (LTRIM(RTRIM(LEFT(APPMSSS,50))))
              end+

        '02'+
         Case when APPMTIN <>'' then 'TIN' 
              when APPMTIN = '' and APPMSSS <> ''  then 'SSS'
              end +

        'PA03A0101'+
        LEN(
        LTRIM(RTRIM(LEFT(APPMADDR1,30))) + ' ' +
        LTRIM(RTRIM(LEFT(APPMADDR2,30)))  + ' '+
        LTRIM(RTRIM(LEFT(APPMADDR3,30))) + ' ' +
        LTRIM(RTRIM(LEFT(APPMADDR4,30)))
        ) +
        LTRIM(RTRIM(LEFT(APPMADDR1,30))) + ' ' +
        LTRIM(RTRIM(LEFT(APPMADDR2,30)))  + ' '+
        LTRIM(RTRIM(LEFT(APPMADDR3,30))) + ' ' +
        LTRIM(RTRIM(LEFT(APPMADDR4,30))) +
        '06'+
        CASE when LEN(LTRIM(RTRIM(APPMZIP))) <= 9 
                then '0'+ LEN(LTRIM(RTRIM(APPMZIP)))
                else  LEN(LTRIM(RTRIM(LEFT(APPMZIP,9))))
                end + LTRIM(RTRIM(LEFT(APPMZIP,9)))+
        '0701R'+
        'A0201'+

        LEN(
        LTRIM(RTRIM(LEFT(APPMEMPA1,30))) + ' ' +
        LTRIM(RTRIM(LEFT(APPMEMPA2,30)))  + ' '+
        LTRIM(RTRIM(LEFT(APPMEMPA3,30))) + ' ' +
        LTRIM(RTRIM(LEFT(APPMEMPA4,30)))
        ) +
        LTRIM(RTRIM(LEFT(APPMEMPA1,30))) + ' ' +
        LTRIM(RTRIM(LEFT(APPMEMPA2,30)))  + ' '+
        LTRIM(RTRIM(LEFT(APPMEMPA3,30))) + ' ' +
        LTRIM(RTRIM(LEFT(APPMEMPA4,30))) +
        '06'+
        CASE when LEN(LTRIM(RTRIM(APPMEMPAZ))) <= 9 
                then '0'+ LEN(LTRIM(RTRIM(APPMEMPAZ)))
                else  LEN(LTRIM(RTRIM(LEFT(APPMEMPAZ,9))))
                end + LTRIM(RTRIM(LEFT(APPMEMPAZ,9)))+
        '0701F'+
        'PH03P01'+
        '03'+
        CASE when LEN(LTRIM(RTRIM(APPMMPHONE))) <= 9 
                then '0'+ LEN(LTRIM(RTRIM(APPMMPHONE)))
                else  LEN(LTRIM(RTRIM(LEFT(APPMMPHONE,30))))
                end + LTRIM(RTRIM(LEFT(APPMMPHONE,30)))+
        '0501F'+
        '0601M'+
        'ES02**' as Textfile

1 个答案:

答案 0 :(得分:0)

    use below correct query


Select 'TUEF'+'11'+(RTRIM(APPMNBR) + SPACE(25 - LEN(APPMNBR)))+
     (RTRIM('') + SPACE(10 - LEN('')))+SPACE(8)+'1000'+'A'+
     ('000010000' + SPACE(9 - LEN('000010000')))+'PHP'+
    'EN'+'08'+'TT'+'009'+'000000'+'NA03N01'
    +'01'+
    CASE when  LEN(LTRIM(RTRIM(APPMFSTNM))) <= 9 
    then '0'+ CONVERT(NVARCHAR(10),LEN(LTRIM(RTRIM(APPMFSTNM))))
    else  CONVERT(NVARCHAR(10),LEN(LTRIM(RTRIM(APPMFSTNM))))
    end +(LTRIM(RTRIM(LEFT(APPMFSTNM,30))))


    +'02'+
    CASE when LEN(LTRIM(RTRIM(APPMMDLNM))) <= 9 
    then '0'+ CONVERT(NVARCHAR(10),LEN(LTRIM(RTRIM(APPMMDLNM))))
    else  CONVERT(NVARCHAR(10),LEN(LTRIM(RTRIM(APPMMDLNM))))
    end +(LTRIM(RTRIM(LEFT(APPMMDLNM,30))))


    +'03'+
    CASE when LEN(LTRIM(RTRIM(APPMLSTNM))) <= 9 
    then '0'+ CONVERT(NVARCHAR(10),LEN(LTRIM(RTRIM(APPMLSTNM))))
    else  CONVERT(NVARCHAR(10),LEN(LTRIM(RTRIM(APPMLSTNM))))
    end
     +(LTRIM(RTRIM(LEFT(APPMLSTNM,30))))

    +'04'+
    CASE when LEN(LTRIM(RTRIM(APPMMOM))) <= 9 
    then '0'+ CONVERT(NVARCHAR(10),LEN(LTRIM(RTRIM(APPMMOM))))
    else CONVERT(NVARCHAR(10), LEN(LTRIM(RTRIM(APPMMOM))))
    end
    +(LTRIM(RTRIM(LEFT(APPMLSTNM,40))))

    +'0608'+
     +(LTRIM(RTRIM(RIGHT(APPMDOB,2))))+
     +(LTRIM(RTRIM(SUBSTRING(APPMDOB,5,2))))+
     +(LTRIM(RTRIM(LEFT(APPMDOB,4))))+

    +'ID03I01'+
     Case when APPMTIN <>'' then
            CASE when LEN(LTRIM(RTRIM(APPMTIN))) <= 9 
            then '0'+ CONVERT(NVARCHAR(10),LEN(LTRIM(RTRIM(APPMTIN))))
            else  CONVERT(NVARCHAR(10),LEN(LTRIM(RTRIM(APPMTIN))) )
            end 


          when APPMTIN = '' and APPMSSS <> ''  then 
            CASE when LEN(LTRIM(RTRIM(APPMSSS))) <= 9 
            then '0'+ CONVERT(NVARCHAR(10),LEN(LTRIM(RTRIM(APPMSSS))))
            else  CONVERT(NVARCHAR(10),LEN(LTRIM(RTRIM(APPMSSS))))
            end 
          end


    + Case when APPMTIN <>'' then (LTRIM(RTRIM(LEFT(APPMTIN,50)))) 
          when APPMTIN = '' and APPMSSS <> ''  then (LTRIM(RTRIM(LEFT(APPMSSS,50))))
          end+

    '02'+
     Case when APPMTIN <>'' then 'TIN' 
          when APPMTIN = '' and APPMSSS <> ''  then 'SSS'
          end +

    'PA03A0101'+
   CONVERT(NVARCHAR(10), LEN(
    LTRIM(RTRIM(LEFT(APPMADDR1,30))) + ' ' +
    LTRIM(RTRIM(LEFT(APPMADDR2,30)))  + ' '+
    LTRIM(RTRIM(LEFT(APPMADDR3,30))) + ' ' +
    LTRIM(RTRIM(LEFT(APPMADDR4,30)))
    ))+
    LTRIM(RTRIM(LEFT(APPMADDR1,30))) + ' ' +
    LTRIM(RTRIM(LEFT(APPMADDR2,30)))  + ' '+
    LTRIM(RTRIM(LEFT(APPMADDR3,30))) + ' ' +
    LTRIM(RTRIM(LEFT(APPMADDR4,30))) +
    '06'+
    CASE when LEN(LTRIM(RTRIM(APPMZIP))) <= 9 
            then '0'+ CONVERT(NVARCHAR(10),LEN(LTRIM(RTRIM(APPMZIP))))
            else  CONVERT(NVARCHAR(10),LEN(LTRIM(RTRIM(LEFT(APPMZIP,9)))))
            end + LTRIM(RTRIM(LEFT(APPMZIP,9)))+
    '0701R'+
    'A0201'+

    CONVERT(NVARCHAR(10),LEN(
    LTRIM(RTRIM(LEFT(APPMEMPA1,30))) + ' ' +
    LTRIM(RTRIM(LEFT(APPMEMPA2,30)))  + ' '+
    LTRIM(RTRIM(LEFT(APPMEMPA3,30))) + ' ' +
    LTRIM(RTRIM(LEFT(APPMEMPA4,30)))
    )) +
    LTRIM(RTRIM(LEFT(APPMEMPA1,30))) + ' ' +
    LTRIM(RTRIM(LEFT(APPMEMPA2,30)))  + ' '+
    LTRIM(RTRIM(LEFT(APPMEMPA3,30))) + ' ' +
    LTRIM(RTRIM(LEFT(APPMEMPA4,30))) +
    '06'+
    CASE when LEN(LTRIM(RTRIM(APPMEMPAZ))) <= 9 
            then '0'+ CONVERT(NVARCHAR(10),LEN(LTRIM(RTRIM(APPMEMPAZ))))
            else  CONVERT(NVARCHAR(10),LEN(LTRIM(RTRIM(LEFT(APPMEMPAZ,9)))))
            end + LTRIM(RTRIM(LEFT(APPMEMPAZ,9)))+
    '0701F'+
    'PH03P01'+
    '03'+
    CASE when LEN(LTRIM(RTRIM(APPMMPHONE))) <= 9 
            then '0'+ CONVERT(NVARCHAR(10),LEN(LTRIM(RTRIM(APPMMPHONE))))
            else  CONVERT(NVARCHAR(10),LEN(LTRIM(RTRIM(LEFT(APPMMPHONE,30)))))
            end + LTRIM(RTRIM(LEFT(APPMMPHONE,30)))+
    '0501F'+
    '0601M'+
    'ES02**' as Textfile