Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 95
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

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