SQL Update statement

Posted on 2014-01-23
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 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

SET              OUTLETTYPE = 'ELEC2'

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.
Question by:bapkins
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
LVL 75

Accepted Solution

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

Author Comment

ID: 39804977
thanks for that

is this bit correct ?

where c.acname like firstName+'%' )

Expert Comment

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?

Featured Post

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.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
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…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

738 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