Solved

Update table based on value in related table

Posted on 2011-09-26
4
234 Views
Last Modified: 2012-05-12
I have 2 tables: aspnet_Users and tblUserProfileData.

Who can I update all users in tblUserProfileData that has one spesific ApplicationId in aspnet_users? The relation between the tables are tblUserProfileData.UserId and aspnet_Users.UserId.

I need to set tblUserProfileData.Payment = '0' where aspnet_Users.ApplicationId = 'aca98bd7-4fee-4bf3-7d21-3b88c9457d57'


This is a select statement that returns all users where I need to set tblUserProfileData.Payment = '0':

SELECT     tblUserProfileData.UserId, tblUserProfileData.Payment, aspnet_Users.ApplicationId
FROM         tblUserProfileData INNER JOIN
                      aspnet_Users ON tblUserProfileData.UserId = aspnet_Users.UserId
WHERE     (aspnet_Users.ApplicationId = 'aca98bd7-4fee-4bf3-7d21-3b88c9457d57')
0
Comment
Question by:webressurs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 36598063
Update A

Set A.Payment = '0'
FROM         tblUserProfileData A INNER JOIN
                      aspnet_Users ON A.UserId = aspnet_Users.UserId
WHERE     (aspnet_Users.ApplicationId = 'aca98bd7-4fee-4bf3-7d21-3b88c9457d57')
0
 
LVL 1

Author Comment

by:webressurs
ID: 36598294
pratima_mcs: When I run the SQL I get the following error:

Column or expression 'Payment' cannot be updated.
SQL Execution Error.
Error Source: .Net.SqlClient Data Provider
Error Message: Invalid object name 'A'

Any clue?
Thanks :)
0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 36598702
are you sure you put the table alias A

Update A

Set A.Payment = '0'
FROM         tblUserProfileData A INNER JOIN
                      aspnet_Users ON A.UserId = aspnet_Users.UserId
WHERE     (aspnet_Users.ApplicationId = 'aca98bd7-4fee-4bf3-7d21-3b88c9457d57')
0
 
LVL 1

Author Closing Comment

by:webressurs
ID: 36707723
Thank you :)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 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