Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8392369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:30:00+00:00 2026-06-09T19:30:00+00:00

Going crazy trying to set a variable in a query of type: SET @idcamposexcluidos=’817,803,495′;

  • 0

Going crazy trying to set a variable in a query of type:

SET @idcamposexcluidos='817,803,495';

so i can then use it on a

WHERE id_campo not in (@idcamposexcluidos)

I’ve tried defining the variable in different formats with no luck and don’t seem to find an specific example for the above:

SET @idcamposexcluidos='(817,803,495)';
...
WHERE id_campo not in @idcamposexcluidos


SET @idcamposexcluidos=817,803,495;

with no success. It either returns an error or ignores the values.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:30:01+00:00Added an answer on June 9, 2026 at 7:30 pm

    You can’t use the IN clause like that. It compiles to a single string in your IN clause. But an IN clause needs separate values.

    WHERE id_campo not in (@idcamposexcluidos)
    

    compiles to

    WHERE id_campo not in ('817,803,495')
    

    but it should be

    WHERE id_campo not in ('817','803','495')
    

    To overcome this either use dynamic SQL or in MySQL you could use FIND_IN_SET:

    SET @idcamposexcluidos='817,803,495';
    ...
    WHERE FIND_IN_SET(id_campo, @idcamposexcluidos) = 0
    

    but using a function like FIND_IN_SET() can not make use of indexes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, I'm not a javascript expert. I'm going crazy on trying to
I'm going crazy trying to write my first php class; it is supposed to
I'm going crazy trying to echo an <img> tag. I want to add this
It's late at night here and I'm going crazy trying to solve a linker
I am trying to set up git on my Debian server. However, I'm going
I'm going crazy trying to make an relative layout work. I was getting an
I am going crazy trying to figure this out. I have tried everything I
I'm going a bit crazy trying to archive and unarchive a UIImageView which has
I've been going stir crazy trying to install the ruby mysql gem here, and
I think I'm going a bit crazy when trying to understand instance variables in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.