Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT WHERE Syntax 1

Status
Not open for further replies.

roycrom

Programmer
Aug 2, 2002
184
GB
Hi, I have been trying to populate my db with data. I have a load of tapes in my "tapes" db. I have fields: "Barcodes", "Pool".

The Barcodes field has entries 0 to 1000. I want to do something similar to the following code, but I can't get the syntax correct.
Code:
INSERT INTO tapeinfo(Pool) values(Primary) WHERE Barcode    > 389 AND < 400
So if the barcode is in the 390's set the pool to primary.

Can anyone give me the syntax for this, pretty much a noob at sql. Thanks for your help.

------------------------------------------
Somethings come from nothing, nothing seems to come from somethings - SFA - Guerilla

roycrom :)
 
Sorry, I didn't notice the rest of your query. It's not very clear what you are trying to do. Can you explain a bit more?
 
Hi,

I have a database called Tapes. One table called tapeinfo. Two fields called Barcode and Pool.

Barcode field is populated with Barcodes from 0 to 1000. I want to insert the string "Primary" into the pool field where the Barcode is 390 to 399

ending up with
Code:
Barcode   |   Pool
---------------------
...
389       |
390       |   Primary
391       |   Primary
<break>
399       |   Primary
400       |
...

Hope this makes it a bit clearer. I tried doing this:
Code:
INSERT INTO tapeinfo(Pool) values(Primary) WHERE Barcode LIKE '39%';

Syntax error near WHERE Barcode.... and this would update barcode 39 too...which I don't want.

------------------------------------------
Somethings come from nothing, nothing seems to come from somethings - SFA - Guerilla

roycrom :)
 
You could use:
[tt]
UPDATE tapeinfo
SET pool="Primary"
WHERE barcode LIKE '39_'
[/tt]
I replaced your '39%' with '39_' to make sure it doesn't match 39 or 3900.
 
Spot on TonyGroves, see my problem now, was using INSERT instead of UPDATE.
So the "_" char matches one single digit or char it take it. Useful to know, thanks a lot for your help.

------------------------------------------
Somethings come from nothing, nothing seems to come from somethings - SFA - Guerilla

roycrom :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top