PC Review


Reply
Thread Tools Rate Thread

HELP with an INSERT INTO statement

 
 
=?Utf-8?B?RnJhbmMgU3V0aGVybGFuZA==?=
Guest
Posts: n/a
 
      1st Aug 2007
Hello everyone,

I received the response below for a previous question. I understand the
logic behind the reply, and I am sure it will work. I can't, however, figure
out what I should be substituting for '2345' in the "SELECT '2345' AS" part
of the solution below?

I'm getting very close to running out of time and would greatly appreciate
any assistance.

Regards,

Franc.

Hi Franc,
>
> Use an append query. Probably you'll need to write VBA code to
> assemble and execute the necessary SQL statement, which could look
> something like this:
>
> INSERT INTO CreditNoteLines (
> CreditNoteID, SalesOrderID, PartNumber, Description,
> Quantity, UnitPrice, Tax)
> SELECT '2345' AS CreditNoteID,
> SalesOrderID, PartNumber, Description,
> Quantity, UnitPrice, Tax)
> FROM SalesOrderLines
> WHERE SalesOrderID = '9876'
> ;
>
>
>
>
> On Tue, 31 Jul 2007 08:42:05 -0700, Franc Sutherland
> <(E-Mail Removed)> wrote:
>
> >Hi,
> >
> >I'm making a sales and invoicing system, but I'm struggling with the credit
> >notes.
> >
> >So far, I have set up the sales orders and sales order lines in two separate
> >tables.
> >
> >Same with the credit notes, and credit note lines.
> >
> >The credit note is based on a sales order, but doesn't necessarily contain
> >all the same lines as there were in the sales order. Therefore, I need to
> >pull through a copy of the sales order lines into the credit note lines, and
> >then edit from there.
> >
> >How do I pull a copy of the sales lines for a particular sales order through
> >into the relevant credit note lines table associated with the original sales
> >order?
> >
> >Thanks,
> >
> >Franc.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?QmVnaW5uZXI=?=
Guest
Posts: n/a
 
      1st Aug 2007
Hi!

If I understand what you are trying to do (selecting data from SalesOrders
and inserting the selected data to CreditNotes), then I think you should:

INSERT INTO CreditNoteLines (
CreditNoteID, SalesOrderID, PartNumber, Description, Quantity, UnitPrice, Tax)
SELECT CreditNoteID,SalesOrderID, PartNumber, Description,Quantity,
UnitPrice, Tax
FROM SalesOrderLines
WHERE SalesOrderID = '9876';

Hope this helps!

- Beginner -



"Franc Sutherland" wrote:

> Hello everyone,
>
> I received the response below for a previous question. I understand the
> logic behind the reply, and I am sure it will work. I can't, however, figure
> out what I should be substituting for '2345' in the "SELECT '2345' AS" part
> of the solution below?
>
> I'm getting very close to running out of time and would greatly appreciate
> any assistance.
>
> Regards,
>
> Franc.
>
> Hi Franc,
> >
> > Use an append query. Probably you'll need to write VBA code to
> > assemble and execute the necessary SQL statement, which could look
> > something like this:
> >
> > INSERT INTO CreditNoteLines (
> > CreditNoteID, SalesOrderID, PartNumber, Description,
> > Quantity, UnitPrice, Tax)
> > SELECT '2345' AS CreditNoteID,
> > SalesOrderID, PartNumber, Description,
> > Quantity, UnitPrice, Tax)
> > FROM SalesOrderLines
> > WHERE SalesOrderID = '9876'
> > ;
> >
> >
> >
> >
> > On Tue, 31 Jul 2007 08:42:05 -0700, Franc Sutherland
> > <(E-Mail Removed)> wrote:
> >
> > >Hi,
> > >
> > >I'm making a sales and invoicing system, but I'm struggling with the credit
> > >notes.
> > >
> > >So far, I have set up the sales orders and sales order lines in two separate
> > >tables.
> > >
> > >Same with the credit notes, and credit note lines.
> > >
> > >The credit note is based on a sales order, but doesn't necessarily contain
> > >all the same lines as there were in the sales order. Therefore, I need to
> > >pull through a copy of the sales order lines into the credit note lines, and
> > >then edit from there.
> > >
> > >How do I pull a copy of the sales lines for a particular sales order through
> > >into the relevant credit note lines table associated with the original sales
> > >order?
> > >
> > >Thanks,
> > >
> > >Franc.

 
Reply With Quote
 
=?Utf-8?B?SmltIEJ1cmtlIGluIE5vdmk=?=
Guest
Posts: n/a
 
      1st Aug 2007
'Beginner' is probably right. The way you have it, with the '2345', will
cause the first field to always have a value of '2345'. I'm assuming you
really want that field to have the value of the CreditNoteID field, whcih is
what you'll get with that Beginner showed you. I think you only want to use
the 'AS' clause if you want a constant as a value (like you had with the
'2345'), or if you are calculating a value (e.g. Field1/Field2), or if you
want to rename a field.

"Franc Sutherland" wrote:

> Hello everyone,
>
> I received the response below for a previous question. I understand the
> logic behind the reply, and I am sure it will work. I can't, however, figure
> out what I should be substituting for '2345' in the "SELECT '2345' AS" part
> of the solution below?
>
> I'm getting very close to running out of time and would greatly appreciate
> any assistance.
>
> Regards,
>
> Franc.
>
> Hi Franc,
> >
> > Use an append query. Probably you'll need to write VBA code to
> > assemble and execute the necessary SQL statement, which could look
> > something like this:
> >
> > INSERT INTO CreditNoteLines (
> > CreditNoteID, SalesOrderID, PartNumber, Description,
> > Quantity, UnitPrice, Tax)
> > SELECT '2345' AS CreditNoteID,
> > SalesOrderID, PartNumber, Description,
> > Quantity, UnitPrice, Tax)
> > FROM SalesOrderLines
> > WHERE SalesOrderID = '9876'
> > ;
> >
> >
> >
> >
> > On Tue, 31 Jul 2007 08:42:05 -0700, Franc Sutherland
> > <(E-Mail Removed)> wrote:
> >
> > >Hi,
> > >
> > >I'm making a sales and invoicing system, but I'm struggling with the credit
> > >notes.
> > >
> > >So far, I have set up the sales orders and sales order lines in two separate
> > >tables.
> > >
> > >Same with the credit notes, and credit note lines.
> > >
> > >The credit note is based on a sales order, but doesn't necessarily contain
> > >all the same lines as there were in the sales order. Therefore, I need to
> > >pull through a copy of the sales order lines into the credit note lines, and
> > >then edit from there.
> > >
> > >How do I pull a copy of the sales lines for a particular sales order through
> > >into the relevant credit note lines table associated with the original sales
> > >order?
> > >
> > >Thanks,
> > >
> > >Franc.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to insert data from datagrid to datasource using insert sql statement sandeep.damodar Microsoft VB .NET 1 16th Mar 2007 01:17 PM
How can i Insert multiple rows by using Insert statement in MS Acc =?Utf-8?B?S2F1c2hpayBTYWhh?= Microsoft Access Queries 3 15th Mar 2005 02:51 PM
What is the use of select statement in insert statement ? cmhasan Microsoft ADO .NET 1 10th Dec 2004 09:12 PM
SQL statement to insert a value generated by a SELECT statement? Rob Richardson Microsoft ADO .NET 2 21st Feb 2004 05:26 PM
How do I insert a NULL value inside an INSERT statement Dino M. Buljubasic Microsoft ADO .NET 10 19th Dec 2003 11:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:14 AM.