Must declare the scalar variable

前端 未结 8 1151
小蘑菇
小蘑菇 2020-11-29 01:41

@RowFrom int

@RowTo int

are both Global Input Params for the Stored Procedure, and since I am compiling the SQL query inside the St

相关标签:
8条回答
  • 2020-11-29 02:19

    You can also get this error message if a variable is declared before a GOand referenced after it.

    See this question and this workaround.

    0 讨论(0)
  • 2020-11-29 02:27

    Just adding what fixed it for me, where misspelling is the suspect as per this MSDN blog...

    When splitting SQL strings over multiple lines, check that that you are comma separating your SQL string from your parameters (and not trying to concatenate them!) and not missing any spaces at the end of each split line. Not rocket science but hope I save someone a headache.

    For example:

    db.TableName.SqlQuery(
        "SELECT Id, Timestamp, User " +
        "FROM dbo.TableName " +
        "WHERE Timestamp >= @from " +
        "AND Timestamp <= @till;" + [USE COMMA NOT CONCATENATE!]
        new SqlParameter("from", from),
        new SqlParameter("till", till)),
        .ToListAsync()
        .Result;
    
    0 讨论(0)
提交回复
热议问题