• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 94
  • Last Modified:

select/update query in same statement

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
razza_b
Asked:
razza_b
1 Solution
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Give us a data mockup of what you're trying to pull off here.
0
 
razza_bAuthor Commented:
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
 
Phillip BurtonDirector, Practice Manager and Computing ConsultantCommented:
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
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
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
 
Phillip BurtonDirector, Practice Manager and Computing ConsultantCommented:
Why Grade C?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now