Sql Query Error

  • Hello,

    I have this query, but i get error when i execute it. Please advise

    Msg 156, Level 15, State 1, Line 1 Incorrect syntax near the keyword 'into'

    exec('select quillivant_HCP_ID [quillivant HCP ID],group_description [Brand Name] '+ @pivotUnique + @pivotUnique1 +@pivotUnique2+

    ' into vouchers.dbo.quillivant_unique_redemptions

    from vouchers.dbo.quillivant_base

    where len(quillivant_HCP_ID) > 0 and quillivant_hcp_id <> ''filtered''

    group by quillivant_HCP_ID,group_description

    order by case when quillivant_HCP_ID = '''' then ''ZZZZZZZZZZZ'' else quillivant_HCP_ID end ,group_description')

    Thanks

  • It seems the value of one of those variables is resulting in the dynamically generated statement's containing a syntax error.

    Without knowing the value of those variables, I couldn't really say what the issue is.

    Instead of using EXECUTE, use PRINT or SELECT to get the actual string generated, and post that. That should make the syntax error more obvious.

    Cheers!

  • Thank you for the reply.. It is bcoz of value of the variables.. I have added another variable @pivotUnique3 and it was working fine..

    Thanks!!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply