Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

A SQL script to search constant with a table in Ms SQL

Posted on 2010-09-17
10
338 Views
Last Modified: 2012-05-10
We need to search various constant value of a column within a table.

The constants are 'okn123', 'OKI987987', 'pop9090' in the Itemcode column of the table.

We want to know if exist in the table
0
Comment
Question by:rayluvs
10 Comments
 
LVL 7

Accepted Solution

by:
tlovie earned 125 total points
ID: 33704068
I think this would work:

select * from Items where Itemcode in ('okn123', 'OKI987987', 'pop9090')
0
 
LVL 16

Assisted Solution

by:vdr1620
vdr1620 earned 125 total points
ID: 33704110
You can do it various ways like

SELECT * FROM TableName
WHERE ItemCode = 'okn123' OR ItemCode =  'OKI987987' OR ItemCode =  'pop9090'

OR

SELECT * FROM TableName
WHERE ItemCode IN ('okn123', 'OKI987987', 'pop9090')
0
 
LVL 12

Assisted Solution

by:jagssidurala
jagssidurala earned 125 total points
ID: 33704224

Declare @Itemcode nvarchar(32)

Select  *  
From    tblItems
Where itemcode like @Itemcode

Here @Itemcode  is a variable by this you can send any of the item code, it will search for the required items.

if you want exact match change the where condition in above query .

Where itemcode = @Itemcode

0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 15

Assisted Solution

by:AmmarR
AmmarR earned 125 total points
ID: 33704280
all methods above seems to do the job, here below is just another way


SELECT *
FROM table
WHERE 
(PATINDEX('okn123', ItemCode ) > 0)
 OR 
(PATINDEX('OKI987987', ItemCode ) > 0)
or
(PATINDEX('pop9090', ItemCode ) > 0)

Open in new window

0
 

Author Comment

by:rayluvs
ID: 33705130
Great, thanx all!
0
 

Author Comment

by:rayluvs
ID: 33705185
Somehow I can reward the points, its saying that I am closing.

please advice
0
 

Author Comment

by:rayluvs
ID: 33705417
Thats exactly what we are doing, but will try again.
0
 

Author Comment

by:rayluvs
ID: 33705438
I dont see that it was rewarded, its asking for a comment to close
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how the fundamental information of how to create a table.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question