Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Insert statement

Posted on 2005-05-07
5
Medium Priority
?
277 Views
Last Modified: 2010-03-19
I'm a newby and I'm sure I'm screwing this up, but I need help anyway.  I'm trying to insert a row into one table from some values from another table.

insert into empty (item_no, description, loc1, loc2,qty_on_hand,qty_on_sales_order,qty_on_purchase_order, closeout) values
      (select no, description, location1, location2, qty_on_hand, qty_on_sales_order, qty_on_purch_order, closeout
       from item where no = '340666')

What am I doing wrong here?  Thanks in advance.
0
Comment
Question by:DarcyAdams
  • 3
5 Comments
 
LVL 34

Assisted Solution

by:arbert
arbert earned 1000 total points
ID: 13951058
insert into empty (item_no, description, loc1, loc2,qty_on_hand,qty_on_sales_order,qty_on_purchase_order, closeout)
select no, description, location1, location2, qty_on_hand, qty_on_sales_order, qty_on_purch_order, closeout
      from item where no = '340666'
0
 
LVL 66

Accepted Solution

by:
Jim Horn earned 1000 total points
ID: 13951061
INSERT INTO empty (item_no, description, loc1, loc2, qty_on_hand, qty_on_sales_order,qty_on_purchase_order, closeout)
SELECT no, description, location1, location2, qty_on_hand, qty_on_sales_order, qty_on_purch_order, closeout
FROM item
WHERE no = '340666'

You use the VALUES command when you are inserting specific values, instead of a SELECT clause.

Hope this  helps.
-Jim
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 13951069
Also, the single quote marks indicate that no is a text-like field (char, varchar).  
If it is numeric and not text, then lose the single quote marks.
0
 

Author Comment

by:DarcyAdams
ID: 13951071
Thank you for you the help.  You guys are seriously fast by the way.
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 13951079
It was a welcome diversion from my current work of trying to figure out how to program back-and-forth between VB-Access and Adobe Acrobat.

Thanks.
-Jim
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Suggested Courses

564 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