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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:17:11+00:00 2026-06-14T11:17:11+00:00

I have a table with 3 fields userID, state, country and I am trying

  • 0

I have a table with 3 fields userID, state, country and I am trying to run a query that finds all records where the country is Great Brittin, Canada or the US and if the country is US I only want records in California, Utah and Arizona.

I thought this might work but no

select  *
from    myTable
where   county in ('GB','CA','US')
  and   case when country = 'US' then  state in ('CA','UT','CA')  end

Any SQL gurus have an idea?

**edit**
I think I tried to over simplify this. The countries and state are passed as variables so not sure if there will be a ‘US’ country but if there is there will be a state list

declare @country varchar(500)
,   @state varchar(500)
,   @sqlStr varchar(4000)

select @sqlStr = 'select * from Addresses
WHERE country IN ('+@country+')
OR (country = ''US'' AND stateCode IN ('+@state+'))'

exec (@sqlStr)

which makes this harder.

  • 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-14T11:17:12+00:00Added an answer on June 14, 2026 at 11:17 am

    replace the last line with something like that:

    and (Country <> 'US' or state in ('ca', 'ut', 'az'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a users table that has the following fields: userid, phone, and address
I have one table, t1, which has fileds called userid, week and year fields.
I have a table tbluser with 2 fields: userid = integer (autoincrement) user =
I have a table with three fields - userID, couponID, last_couponID. When the user
I have a table containing several fields. The primary key is userId . Currently
I have Statistic table with these fields Id UserId DateStamp Data Also there is
They both have fileId and userId fields table 1: fileId userId table 2: fileId
I have a table, mealdb , which has three fields viz. userid, timeofday, daydate
I have table with permissions that has few bit fields. I want to group
I have a table with fields user_id and votes . The votes field is

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.