select/update query in same statement

Posted on 2015-01-13
Last Modified: 2015-01-19
Can anyone help me please,

I have a query where i do the select below, and now i need another query to update the same select fields based on the joining SO_Number...

1st query...

  FROM [PartDetail]  pd
  left JOIN [DataLink] ON [DataLink].Material = pd.Material
  WHERE SO_Number='0002424291'

2nd query...(this is what i need to update everything above) so i would be supplying the query with params that match the fields in pd.

Question by:razza_b
LVL 65

Expert Comment

by:Jim Horn
ID: 40547385
Give us a data mockup of what you're trying to pull off here.

Author Comment

ID: 40547570
ok so i have 2 tables and one has these fields...

partdetail table (these fields need to be updated based on the SO_Number on table [DataLink])

DataLink table

so when i do the select query i bring that back to my app and i change the values and then want to update that same data back again.
hope this helps.
LVL 24

Accepted Solution

Phillip Burton earned 500 total points
ID: 40548491
Just prefix your existing statement with

UPDATE tabletoupdate
SET fieldname = newvalue

so it continues


You can test it with starting


and end with

Select * from updatedtable
LVL 47

Expert Comment

by:Vitor Montalvão
ID: 40548840
You want to retrieve data, change some values and update the data, right?
If so, you need to tell us which programming language are you using so we can help you better.
LVL 24

Expert Comment

by:Phillip Burton
ID: 40557433
Why Grade C?

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Replication question 9 43
Simple SQL query from two tables 13 54
Need help how to find where my error is in UFD 6 30
syntax sql error 2 14
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

803 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