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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:37:19+00:00 2026-05-25T09:37:19+00:00

if(OBJECT_ID(‘EgTb’)is not null)drop table [EgTB]; GO create table [EgTB](Name varchar(50),country varchar(50)) insert into EgTB

  • 0
if(OBJECT_ID('EgTb')is not null)drop table [EgTB];
GO
create table [EgTB](Name varchar(50),country varchar(50))
insert into EgTB values('aaa','sg');
insert into EgTB values('bbb','uk');
insert into EgTB values('ccc','us');
insert into EgTB values('ddd','au');
GO
select * from EgTB;

declare @cou varchar(50), @firstCou varchar(50), @secondCou varchar(50);
set @firstCou='sg';
set @secondCou='uk';
if(@cou is null)
begin
set @cou=@firstCou+','+@secondCou;
end
select * from EgTB where (@cou is null or country in (@cou));
GO
if(OBJECT_ID('EgTb')is not null)drop table [EgTB];
GO

The above code is the one I stimulated.

there is a variable @cou.

That variable is the one using in where.

what I want is.. if @cou is null, I want to use @firstCou and @secondCou.

Instead of doing where country in (@firstCou,@secondCou)

I want where country in (@cou) with those 2 variable values in @cou.

cos the real thing is not 2 extra variable.. I will retreieve several records and I won’t know the fixed record.

That’s why I want to use IN()

But my problem is when I add those 2 values into @cou, the @cou value becomes 'sg,uk' instead of 'sg','uk'.

it is expected but how can i make it so that it becomes 'sg','uk'

  • 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-25T09:37:20+00:00Added an answer on May 25, 2026 at 9:37 am

    You can not replace the parameters for IN with a string literal. In takes a list of expressions or a sub-query as an argument.

    You could use a table variable instead with one column and one row for each country.

    declare @cou table(country varchar(50))
    

    Insert the countries you look for to the table variable and use a query that looks like this.

    select *
    from EgTB
    where country in (select country from @cou)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's some sample code: if object_id('tempdb..#TempList') is not null drop table #TempList create table
USE AdventureWorks; GO IF OBJECT_ID (N'dbo.AWBuildVersion', N'U') IS NOT NULL DROP TABLE dbo.AWBuildVersion; GO
Now I am using something like: IF (object_id('table', 'U') is not null) AND (NOT
I'm trying to run the following SQL statement: IF OBJECT_ID('MyTable') IS NOT NULL DROP
Given the following: if object_id('MyTable') is null create table MyTable( myColumn int ) Is
I have the following table: if object_id(N'dbo.Node') is null create table dbo.Node ( ID
I have the following table: if object_id(N'dbo.Node') is null create table dbo.Node ( ID
I have a simple MEDIAN calculation function: IF OBJECT_ID(N'COMPUTEMEDIAN', N'FN') IS NOT NULL DROP
With the following Stored Procedure in SQL Server 2005 IF OBJECT_ID('[dbo].[UserProfile]') IS NOT NULL
I have a table declaration: TYPE PERSON_TYPE AS OBJECT (ID NUMBER(38), NAME VARCHAR2(20)); TYPE

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.