zoukankan      html  css  js  c++  java
  • 郁闷了,SQL SERVER为什么报这个错啊Incorrect syntax near

    这个是我的存储过程

    CREATE PROCEDURE [dbo].[Pagination]
    @Columns VARCHAR(500), -- The columns to be displayed, divide by comma
    @Tablename VARCHAR(100), -- The name of the table to be searched
    @OrderColumnName VARCHAR(100), -- The name of the column to be used in order
    @Order VARCHAR(50), -- The order method, ASC or DESC
    @Where VARCHAR(100), -- The where condition, if there is not conditon use 1=1
    @PageIndex INT, -- Current page index
    @PageSize INT, -- The size of the page
    @PageCount INT OUTPUT -- The total page count,define as output parameter
    AS
    BEGIN
    DECLARE @SqlRecordCount NVARCHAR(100) -- The SQL Statement to get the total count of the records
    DECLARE @SqlSelect NVARCHAR(1000) -- The SQL SELECT statment
    SET @SqlRecordCount = N'SELECT @RecordCount = COUNT(*) FROM' + @Tablename + ' WHERE ' +@Where
    DECLARE @RecordCount INT
    EXEC sp_executesql @SqlRecordCount, N'@RecordCount INT OUTPUT',@RecordCount OUTPUT -- Transfer the parameter dynamic
    
    IF(@RecordCount % @PageSize = 0)
    SET @PageCount = @RecordCount / @PageSize
    ELSE
    SET @PageCount = @RecordCount / @PageSize + 1
    
    SET @SqlSelect = N'SELECT ' + @Columns + ' FROM(SELECT ROW_NUMBER() OVER (ORDER BY ' + @OrderColumnName
        +' ' + @Order + ') AS tempid, * FROM ' 
        + @Tablename + ' WHERE ' + @Where + ') AS tempTableName WHERE tempid
        BETWEEN ' + STR((@PageIndex - 1)*@PageSize + 1) + ' AND ' + STR(@PageIndex * @PageSize)
    EXEC(@SqlSelect)
    END

    运行下面这个的时候

    DECLARE @PageCount int
    EXEC Pagination    'fname','employee','fname','DESC','1=1',1,20,@PageCount
    

    SQL SERVER 报这个错误

    Msg 102, Level 15, State 1, Line 1
    Incorrect syntax near 'FROMemployee'. 
    
    (20 row(s) affected)
    

    有Result 返回,但是为什么报这么一个错误啊。

    Debug 了下

    这个是动态的生成的SQL语句

    SELECT fname FROM(SELECT ROW_NUMBER() OVER (ORDER BY fname DESC) AS tempid, * FROM employee WHERE 1=1) AS tempTableName WHERE tempid
        BETWEEN          1 AND         20
    

    这句话我单独在SQL SERVER分析查询器里,运行没有错误,但是在存储过程里为什么有这个错误(⊙o⊙)?

  • 相关阅读:
    结对项目 sport club(一)
    结对项目 sport club(三)
    结对项目 sport club(二)
    博客作业
    学生信息管理系统APP需求分析
    随机生成四则运算
    软件介绍
    利用纯css写三角形,弧度箭头,吃豆人,气泡。放大镜,标签的源码
    js中的数据类型隐式转换的三种情况
    javascript基础入门之js中的结构分支与循环语句
  • 原文地址:https://www.cnblogs.com/herbert/p/1785118.html
Copyright © 2011-2022 走看看