Solved

SQL Update statement

Posted on 2014-01-23
3
56 Views
Last Modified: 2015-06-17
Hi All,
I have two sql tables in a database.

Companies - contains acname (account name), outlettype
FirstNames - contains 1 column called 'names'

I have a list of our customers in the companies table.
I have a list of individuals first names in the Firstnames table.

I want to
update companies.outlettype to ELEC2 if the acname begins (starts) with any of the names exists in the firstnames.name column

basically i am trying to seperate individuals from companies to segment the data for marketing by updating the outlettype.

I have been doing the following statement on individual records using the following

UPDATE    ACOCMP1.COMPANIES
SET              OUTLETTYPE = 'ELEC2'
WHERE     (ACNAME LIKE 'john %') AND (OUTLETTYPE IS NULL)

But i would like to do this on a large scale with 5495 first names that i have obtained in the FirstNames table

There are around 80,000 records in my companies table so doing them all manually will take a little time :-)

I would be grateful if you could help me with the query to do this mass update.
0
Comment
Question by:bapkins
3 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 39804584
UPDATE   c
SET              OUTLETTYPE = 'ELEC2'
FROM  ACOCMP1.COMPANIES  c
WHERE EXISTS  (SELECT 1 FROm Firstnames  where c.acname like firstName+'%' )
0
 

Author Comment

by:bapkins
ID: 39804977
thanks for that

is this bit correct ?

where c.acname like firstName+'%' )
0
 
LVL 1

Expert Comment

by:Multimatic
ID: 39806598
To append the % for the wild card search, use CONCAT:

For example:

SELECT 1 FROm Firstnames  where c.acname like LIKE CONCAT(firstName,'%')

Whoops sorry, that was MYSQL syntax.... think that is fine for MSSQL?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now