Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Help on a Query Logic


Help on a Query Logic

Author
Message
soobaashh
soobaashh
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
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
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16550 Visits: 17004
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)
RandomEvent
RandomEvent
Mr or Mrs. 500
Mr or Mrs. 500 (569 reputation)Mr or Mrs. 500 (569 reputation)Mr or Mrs. 500 (569 reputation)Mr or Mrs. 500 (569 reputation)Mr or Mrs. 500 (569 reputation)Mr or Mrs. 500 (569 reputation)Mr or Mrs. 500 (569 reputation)Mr or Mrs. 500 (569 reputation)

Group: General Forum Members
Points: 569 Visits: 401
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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search