0

Does anyone knows how to solve this problem bellow ?

enter image description here

I dont know how to put variable in where condition in a dynamic sql command .

EDITED

I put autofipe ddl right here

enter image description here

SQL 2014 i am using

Thanks in advance

Luiz
  • 141
  • 2
  • 14
  • 2
    Post your code as plain text, not an image. See https://stackoverflow.com/help/formatting for code formatting help. – Barmar Jun 27 '18 at 15:47
  • Please post plain text. We are going to re-type all those lines. – Eric Jun 27 '18 at 15:56
  • Debugging is part of programmer's job!! Have you tried to `PRINT @sqlText` before running the query???? If you have, it easy to see why your query doesn't run. – Eric Jun 27 '18 at 15:58
  • On the error message, there is value "038003-2" , but i am trying to look at the code snippet and i cannot find that value to any variable, what i saw is "006017-8 on line 6.. it is better if you will copy that code (as plain text) for easier understanding of the problem. – japzdivino Jun 27 '18 at 16:09
  • Also, if you want to debug and check the value of your @sqlText , you can perform select to validate the final value of that variable, before proceeding to exec command. – japzdivino Jun 27 '18 at 16:12
  • It looks like the cod_fipe column in tAutoFipe is datatype int, no? – S3S Jun 27 '18 at 19:03
  • cod_fipe its not int , is varchar , as i showed up above – Luiz Jun 28 '18 at 11:46
  • `SELECT TOP 1 ANO....` whats the datatype of `ANO` column?? – Jaydip Jadhav Jun 28 '18 at 11:53

1 Answers1

1

I believe this question has already been answered here: SQL Server - In clause with a declared variable [duplicate]

Also, I'm not expert in SQL, but it feels like you didn't assign a value to @cod_fipe before using it, shouldn't that be SET @cod_fipe = ... instead of SELECT @cod_fipe = ...?

JeyzerMC
  • 141
  • 5