Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Help on a Query Logic Expand / Collapse
Author
Message
Posted Tuesday, August 27, 2013 6:50 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, August 28, 2013 9:55 PM
Points: 1, Visits: 3
Hi All,

I have 3 tables with the below Structure.

Table - 1
Cust_ID
Order_Date
Order_time
Cust_Name
Cust_Address
Order_Status
Emp_ID
Cust_Prod_Cost
Cust_Balance


Table - 2
Cust_ID
Delivered_Time
Delivered_Qty
Payment_Type
Cust_Prod_Cost
Cust_Balance
Amount_Paid
Order_Status
Emp_ID
WHID

Table - 3
Cust_ID
Order_Date
Order_time
Delivery_Time
Cust_Prod_Cost
Delivered_Qty
Payment_Type
Amt_To_Pay
Amount_Paid
Due_Amount
Order_Status
Emp_ID
WHID


Now i would like to insert the data from Table - 1 and 2 into Table -3 when Table2-Cust_ID=Table1.Cust_ID and Table2.Order_Status='0'

Can you please help me out with an SQL Query??. I tried many possible ways, but with no result
Post #1488730
Posted Tuesday, August 27, 2013 7:54 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:41 PM
Points: 13,315, Visits: 12,182
Hi and welcome to SSC. I would love to help you but you haven't provided enough information for me to help. In order to help we will need a few things:

1. Sample DDL in the form of CREATE TABLE statements
2. Sample data in the form of INSERT INTO statements
3. Expected results based on the sample data

Please take a few minutes and read the first article in my signature for best practices when posting questions.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1488781
Posted Tuesday, August 27, 2013 8:07 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Thursday, August 28, 2014 3:25 AM
Points: 519, Visits: 165
Possibly the easiest method here providing the table schema is setup correctly is to write your insert as a 'select' statement so in this case possibly along the lines of

SELECT <column 1>,<column 2>,<column 3> .......
FROM Table1 left outer join Table2
WHERE <Enter Clause Required>

once you have the data correct add and 'Insert into Table3' clause above the select to insert into Table 3. Just make sure the columns in your select match the columns in your table.

Its noit bullet proof but should put you on the right track.
Post #1488791
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse