Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Simple-ish SQL Script required !!

Thread Tools
 
Search this Thread
 
Old Aug 23, 2002 | 12:01 PM
  #1  
DJ Dunk's Avatar
DJ Dunk
Thread Starter
Moderator
20 Year Member
iTrader: (5)
 
Joined: Nov 2001
Posts: 17,864
Likes: 0
From: Not all those who wander are lost
Lightbulb

Can someone help me out with a simple SQL script to update a table ?

You can ? Great ! Okay here's the details . . . .

I need to update the field called Box_Contents in a table called boxes051001 with the data held in a field of the same name in a table called boxes403010 where the field barcode matches in both tables.

Probably really simple, but its Friday
Reply
Old Aug 23, 2002 | 12:06 PM
  #2  
Dream Weaver's Avatar
Dream Weaver
Scooby Regular
25 Year Member
Liked
 
Joined: Feb 2000
Posts: 9,846
Likes: 4
From: Lancashire
Post

just a guess but along the lines of:

dim var1, var2, var3, var4

var1 = boxes051001.Box_Contents
var2 = boxes403010.Box_Contents
var3 = boxes051001.barcode
var4 = boxes403010.barcode

update var1 values (var2) where var3 = var4

Just a guess as I am still learning this stuff - Fosters/Chiark are your men


Box_Contents in a table called boxes051001 with the data held in a field of the same name in a table called boxes403010 where the field barcode matches in both tables.


[Edited by Dream Weaver - 8/23/2002 12:16:46 PM]
Reply
Old Aug 23, 2002 | 12:07 PM
  #3  
Dream Weaver's Avatar
Dream Weaver
Scooby Regular
25 Year Member
Liked
 
Joined: Feb 2000
Posts: 9,846
Likes: 4
From: Lancashire
Post

ps couldn't be arsed writing the acutal syntax out
Reply
Old Aug 23, 2002 | 12:10 PM
  #4  
DJ Dunk's Avatar
DJ Dunk
Thread Starter
Moderator
20 Year Member
iTrader: (5)
 
Joined: Nov 2001
Posts: 17,864
Likes: 0
From: Not all those who wander are lost
Wink

In theory thats exactly what I'm after But it's the syntax that I'm stuck on
Reply
Old Aug 23, 2002 | 12:17 PM
  #5  
GaryK's Avatar
GaryK
Scooby Regular
 
Joined: Sep 1999
Posts: 4,037
Likes: 0
From: Bedfordshire
Post


UPDATE boxes051001
SET Box_Contents = boxes403010.Box_Contents
WHERE
boxes051001.barcode = boxes403010.barcode

I think???

Gary
Reply
Old Aug 23, 2002 | 12:20 PM
  #6  
PiNkEyE69's Avatar
PiNkEyE69
Scooby Regular
 
Joined: Apr 2002
Posts: 3,838
Likes: 0
Talking

try this...

update boxes051001 set boxes051001.box_contents = boxes403010.box_contents from boxes051001,boxes403010 where boxes051001.barcode = boxes403010.barcode

Difficult to test here without the tables
Reply
Old Aug 23, 2002 | 12:22 PM
  #7  
V5's Avatar
V5
Scooby Regular
 
Joined: Jul 2002
Posts: 1,933
Likes: 0
Post

update boxes051001 set Box_Contents =
(select Box_Contents from boxes403010
where boxes403010.barcode = boxes051001.barcode)

I think (This is coming from an Oracle point of view, but think it would work even if it's SQL Server you're after)

And remember to commit!
Reply
Old Aug 23, 2002 | 12:25 PM
  #8  
PiNkEyE69's Avatar
PiNkEyE69
Scooby Regular
 
Joined: Apr 2002
Posts: 3,838
Likes: 0
Talking

Just tried my script on 2 tables I created and it works.
Reply
Old Aug 23, 2002 | 12:26 PM
  #9  
DJ Dunk's Avatar
DJ Dunk
Thread Starter
Moderator
20 Year Member
iTrader: (5)
 
Joined: Nov 2001
Posts: 17,864
Likes: 0
From: Not all those who wander are lost
Thumbs up

Sorry, forgot to mention its Oracle 8i

Will give these a go. Thanks for your help
Reply
Old Aug 23, 2002 | 12:29 PM
  #10  
DJ Dunk's Avatar
DJ Dunk
Thread Starter
Moderator
20 Year Member
iTrader: (5)
 
Joined: Nov 2001
Posts: 17,864
Likes: 0
From: Not all those who wander are lost
Talking

Gold stars all round
Reply
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
Abx
Subaru
22
Jan 9, 2016 05:42 PM
gazzawrx
Non Car Related Items For sale
13
Oct 17, 2015 06:51 PM
FuZzBoM
Wheels, Tyres & Brakes
16
Oct 4, 2015 09:49 PM
buckerz69
Wanted
2
Oct 3, 2015 09:54 PM
Pro-Line Motorsport
Car Parts For Sale
2
Sep 29, 2015 07:36 PM




All times are GMT +1. The time now is 10:28 AM.