Solved

select/update query in same statement

Posted on 2015-01-13
5
80 Views
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...

SELECT
      pd.[Material]
      ,pd.[Description]
      ,pd.[Serialised]
      ,pd.[ProductNo]
      ,pd.[PartNo]
  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.


Thanks
0
Comment
Question by:razza_b
5 Comments
 
LVL 65

Expert Comment

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

Author Comment

by:razza_b
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])
 -----------------------
[Material]
[Description]
[Serialised]
[ProductNo]
[PartNo]

DataLink table
--------------------
SO_Number

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.
0
 
LVL 24

Accepted Solution

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

UPDATE tabletoupdate
SET fieldname = newvalue

so it continues

SELECT ...

You can test it with starting

BEGIN TRAN

and end with

Select * from updatedtable
ROLLBACK TRAN
0
 
LVL 45

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.
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40557433
Why Grade C?
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now