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 6613357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:12:33+00:00 2026-05-25T20:12:33+00:00

I need help with the following query. I want to put a condition on

  • 0

I need help with the following query. I want to put a condition on the returned value of select command which is an integer between 0 and any number.

DECLARE @month varchar(50);
set @month ='01-03-05-07-09-11'; <---  clarification: these are all months

Declare @cur_month int;
set @cur_month = Month(GetDate());

select charindex(str(@cur_month), @month);

I essentially want

If ( select charindex(str(@cur_month), @month))
    // successful

I get error

An expression of non-boolean type specified in a context where a
condition is expected, near ‘print’.

I tried CAST and CONVERT but to no Avail. As you can see, I am trying to see if the current month is in my @month field, I want to execute certain actions if it is.

  • 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-05-25T20:12:34+00:00Added an answer on May 25, 2026 at 8:12 pm

    Taking the answer from @PaulStock with a couple tweaks will work better.

    Changes from PaulStock’s answer

    • Left pad for leading zeros. 2 != 02 and wouldn’t match.
    • Add hyphens at the beginning and end of the string so each value is in the form -XX- I included this in case you realize you won’t be having the leading zeros. If you’ll always have leading zeros you won’t need this.

    Actual code

    DECLARE @month VARCHAR(50);
    set @month ='03-05-12-09';
    
    set @month = '-' + @month + '-'
    
    IF CHARINDEX('-' + right('00' + CAST(MONTH('2/13/2011') AS VARCHAR), 2) + '-', @month) > 0
        PRINT 'exists'
    ELSE 
        PRINT 'does not exist'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help with this query: I want to delete the following rows
I need help with a raw SQL query which gets a value based on
I would really appreciate any help with the following problem: I need to be
I need help with the following query. create table #table1 (id int not null
can someone please help me with the following query i need to update a
I need help building a mysql query to select from multiple tables. I have
I need help to write a MySQL query that would do the following for
I need some help with query from multiple tables. My database: I have following
I need help doing the following: a preprocessor macro label(x) shall output #x, e.g.,
I need some help extracting the following bits of information using regular expressions. Here

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.