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 23 August 2002, 12:01 PM
  #1  
DJ Dunk
Moderator
Support Scoobynet!
Thread Starter
iTrader: (5)
 
DJ Dunk's Avatar
 
Join Date: Nov 2001
Location: Not all those who wander are lost
Posts: 17,863
Received 0 Likes on 0 Posts
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
Old 23 August 2002, 12:06 PM
  #2  
Dream Weaver
Scooby Regular
 
Dream Weaver's Avatar
 
Join Date: Feb 2000
Location: Lancashire
Posts: 9,844
Received 0 Likes on 0 Posts
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]
Old 23 August 2002, 12:07 PM
  #3  
Dream Weaver
Scooby Regular
 
Dream Weaver's Avatar
 
Join Date: Feb 2000
Location: Lancashire
Posts: 9,844
Received 0 Likes on 0 Posts
Post

ps couldn't be arsed writing the acutal syntax out
Old 23 August 2002, 12:10 PM
  #4  
DJ Dunk
Moderator
Support Scoobynet!
Thread Starter
iTrader: (5)
 
DJ Dunk's Avatar
 
Join Date: Nov 2001
Location: Not all those who wander are lost
Posts: 17,863
Received 0 Likes on 0 Posts
Wink

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


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

I think???

Gary
Old 23 August 2002, 12:20 PM
  #6  
PiNkEyE69
Scooby Regular
 
PiNkEyE69's Avatar
 
Join Date: Apr 2002
Posts: 3,838
Likes: 0
Received 0 Likes on 0 Posts
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
Old 23 August 2002, 12:22 PM
  #7  
V5
Scooby Regular
 
V5's Avatar
 
Join Date: Jul 2002
Posts: 1,933
Likes: 0
Received 0 Likes on 0 Posts
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!
Old 23 August 2002, 12:25 PM
  #8  
PiNkEyE69
Scooby Regular
 
PiNkEyE69's Avatar
 
Join Date: Apr 2002
Posts: 3,838
Likes: 0
Received 0 Likes on 0 Posts
Talking

Just tried my script on 2 tables I created and it works.
Old 23 August 2002, 12:26 PM
  #9  
DJ Dunk
Moderator
Support Scoobynet!
Thread Starter
iTrader: (5)
 
DJ Dunk's Avatar
 
Join Date: Nov 2001
Location: Not all those who wander are lost
Posts: 17,863
Received 0 Likes on 0 Posts
Thumbs up

Sorry, forgot to mention its Oracle 8i

Will give these a go. Thanks for your help
Old 23 August 2002, 12:29 PM
  #10  
DJ Dunk
Moderator
Support Scoobynet!
Thread Starter
iTrader: (5)
 
DJ Dunk's Avatar
 
Join Date: Nov 2001
Location: Not all those who wander are lost
Posts: 17,863
Received 0 Likes on 0 Posts
Talking

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



Quick Reply: Simple-ish SQL Script required !!



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