Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Sql update statement

Posted on 2014-11-05
3
Medium Priority
?
187 Views
Last Modified: 2014-11-05
I have the following sql update statement that I need to run.  

I am not sure this is written correctly and was looking for some help.  

update binlocat
set LICENSE_PLATE = UPLOAD.FIELD034
where SUBSTRING(BINLOCAT.EXTENDED, 102, 8) = UPLOAD.FIELD021 and
                  (UPLOAD.FIELD001='st') AND (UPLOAD.FIELD003='05') AND
                   (UPLOAD.FIELD008 like '10pl%')
0
Comment
Question by:notasgoodasyou
  • 2
3 Comments
 
LVL 66

Accepted Solution

by:
Jim Horn earned 2000 total points
ID: 40424292
Since this UPDATE statement has two tables, binlocal and UPLOAD, then it needs a FROM and JOIN that spell out how the two tables are related.  Something like (replace id with the column that joins these two tables)...
update binlocat
set LICENSE_PLATE = UPLOAD.FIELD034
FROM binlocat
   JOIN UPLOAD ON binlocat.id = UPLOAD.id
where SUBSTRING(BINLOCAT.EXTENDED, 102, 8) = UPLOAD.FIELD021 and 
   (UPLOAD.FIELD001='st') AND 
   (UPLOAD.FIELD003='05') AND
   (UPLOAD.FIELD008 like '10pl%')

Open in new window

0
 

Author Comment

by:notasgoodasyou
ID: 40424305
Thanks Jim

Will the following work?


update binlocat
set LICENSE_PLATE = UPLOAD.FIELD034
FROM binlocat
   JOIN UPLOAD ON SUBSTRING(BINLOCAT.EXTENDED, 102, 8) = UPLOAD.FIELD021
where SUBSTRING(BINLOCAT.EXTENDED, 102, 8) = UPLOAD.FIELD021 and
   (UPLOAD.FIELD001='st') AND
   (UPLOAD.FIELD003='05') AND
   (UPLOAD.FIELD008 like '10pl%')
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 40424342
Should work, although if you are joining on the SUBSTRING.. expression then you don't need the same expression in the WHERE clause.  

I don't have a connection to your data source, so I can't check for things like table and column names spelled correctly, data types, etc.

Check out the T-SQL below, and note the use of table aliases (b and u), indenting, and removed some unnecessary parentheses to make it much more readable.
update b
set b.LICENSE_PLATE = u.FIELD034
FROM binlocat b
   JOIN UPLOAD u ON SUBSTRING(b.EXTENDED, 102, 8) = u.FIELD021 
where
   u.FIELD001='st' AND 
   u.FIELD003='05' AND
   u.FIELD008 like '10pl%'

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
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…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

972 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