An expression of non-boolean type specified in a context where a condition is expected

Naami.Ayman 331 Reputation points
2021-05-07T11:06:17.85+00:00

Hi,

I have an issue with this stored procedure (code below), it returns me the following error:

An expression of non-boolean type specified in a context where a condition is expected, near 'seque'.

Can you please help me with it ?
Thank you

DECLARE @table_name nvarchar(max);
    DECLARE @sequence nvarchar(max);
    DECLARE @batch_no nvarchar(max);
    DECLARE @SQL nvarchar(500);
    DECLARE @ParmDef nvarchar(500)

    SELECT @SQL ='select @batch_no_output=(select max(batch_no) from [glb_ops_tsq_audit].[batch]), @table_name_out=a.table_name, @sequence_out=a.sequence from [glb_ops_tsq_audit].[table_config] a
    left join (select table_name,sequence,max_batch from (select table_name,sequence,max(batch_no) max_batch from [glb_ops_tsq_audit].[batch_processing_log]
    group by table_name,sequence) a 
    where max_batch=(select(max(batch_no)) aa from [glb_ops_tsq_audit].[batch])) b
    on trim(a.table_name)=trim(a.table_name) and a.sequence=b.sequence
    where b.table_name is null'  ;

    SET @ParmDef = N'@table_name_out nvarchar(max) OUTPUT,@sequence_out nvarchar(max) OUTPUT,@batch_no_output nvarchar(max) OUTPUT';

    EXEC sp_executesql @SQL, @ParmDef, @table_name_out=@table_name OUTPUT,@sequence_out=@sequence OUTPUT,@batch_no_output=@batch_no OUTPUT;
    select @batch_no, @table_name ,@sequence
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,490 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,690 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 120.1K Reputation points
    2021-05-07T11:12:37.31+00:00

    Try increasing the size:

    DECLARE @SQL nvarchar(max)
    

    Show the new errors, if any.


2 additional answers

Sort by: Most helpful
  1. Stefan Hoffmann 621 Reputation points
    2021-05-07T11:16:10.493+00:00

    Start by correcting the SQL statement in @alenzi . Run it standalone to get it right.

    btw, you don't need dynamic SQL in general here.


  2. Naami.Ayman 331 Reputation points
    2021-05-07T11:37:55.357+00:00

    Hi,

    The issue was in @alenzi value declared with limit of 500, I changed it to max and the stored proc worked fine.

    Thank you all for your help.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.