473,395 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

SQL Update with join

Someone please help. I'm running the following SQL query in sql server 2000...

UPDATE S
SET S.[Dept Request] = B.[BY Request]
FROM [Budget Details - 2007] B LEFT OUTER JOIN
[SCI Transaction Summary] S ON B.[Account Key] = S.Account
WHERE (S.[Year] = 2007)

All it does is zero out the field I'm trying to update. I'm almost positive the syntax is 100% correct, but then again it is nearing the end of the day...
Thanks for any help!
Apr 3 '08 #1
7 2462
ck9663
2,878 Expert 2GB
Someone please help. I'm running the following SQL query in sql server 2000...

UPDATE S
SET S.[Dept Request] = B.[BY Request]
FROM [Budget Details - 2007] B LEFT OUTER JOIN
[SCI Transaction Summary] S ON B.[Account Key] = S.Account
WHERE (S.[Year] = 2007)

All it does is zero out the field I'm trying to update. I'm almost positive the syntax is 100% correct, but then again it is nearing the end of the day...
Thanks for any help!

Try this:

Expand|Select|Wrap|Line Numbers
  1. UPDATE S
  2. SET  [Dept Request] = B.[BY Request]
  3. FROM [Budget Details - 2007] B 
  4. LEFT OUTER JOIN [SCI Transaction Summary] S ON B.[Account Key] = S.Account
  5. WHERE     (S.[Year] = 2007)

-- CK
Apr 3 '08 #2
Thanks for the quick response CK...but that was what I originally tried. It had the same results as the query i posted. any other suggestions?
Apr 4 '08 #3
ck9663
2,878 Expert 2GB
What's your error again?

-- CK
Apr 4 '08 #4
It does not create an error, rather it updates the [Dept Request] field to 0 where the inner join is true and <null> where the inner join is false. It should be updating this field to the value of [BY Request] from the joined table.
Apr 4 '08 #5
ck9663
2,878 Expert 2GB
Do a distinct value on the [BY Request] and check the values.

-- CK
Apr 4 '08 #6
I actually tried that as well...and ran a select query on the tables just to make sure the values were being picked up correctly. All seemed well. The frustration and time wasted got the better of me...I cheated by exporting the data to an access mdb, making the conversions and re-importing the data back into the sql server. This doesn't mean i wouldn't like to figure this out if you have any other suggestions. thanks.
-Jay
Apr 5 '08 #7
ck9663
2,878 Expert 2GB
try this:

Expand|Select|Wrap|Line Numbers
  1. UPDATE [SCI Transaction Summary]
  2. SET  [Dept Request] = B.[BY Request]
  3. FROM [SCI Transaction Summary] 
  4. LEFT OUTER JOIN [Budget Details - 2007] B 
  5.  ON B.[Account Key] = [SCI Transaction Summary].Account
  6. and [SCI Transaction Summary].[Year] = 2007
  7.  
-- CK
Apr 5 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Narine | last post by:
Hi All, I need to write one complicated update statement and I'm looking at maybe finding a simpler way to do it. I have 2 tables: 1.Photo Table PhotoID FileName 1 111.jpg
17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
2
by: serge | last post by:
/* This is a long post. You can paste the whole message in the SQL Query Analyzer. I have a scenario where there are records with values pointing to wrong records and I need to fix them using an...
9
by: Vorpal | last post by:
Here is a small sample of data from a table of about 500 rows (Using MSSqlserver 2000) EntryTime Speed Gross Net ------------------ ----- ----- 21:09:13.310 0 0 0 21:09:19.370 9000 ...
4
by: 001 | last post by:
Hello, The select statement needs only 1 second to complete the query. But the update statement spends 30 minutes. Why? SELECT STATEMENT: declare @IDate smalldatetime select @IDate=col001...
2
by: Mike Leahy | last post by:
Hello all, This question is related to updating tables - is there any way to calculate or update the values in a column in a table to the values in a field produced by a query result? An...
4
by: deko | last post by:
I'm trying to update the address record of an existing record in my mdb with values from another existing record in the same table. In pseudo code it might look like this: UPDATE tblAddress SET...
2
by: Sim Zacks | last post by:
The following query updated all the rows in the AssembliesBatch table, not just where batchID=5. There are 2 rows in the AssembliesBatch table with batch ID of 5 and I wanted to update both of...
0
by: svgeorge | last post by:
I want to update several tables using one stored procedure. How can i do this I mean the syntax.etc. declaration etc. I know the basic syntax as below CREATE PROCEDURE <Procedure_Name, sysname,...
3
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.