Solved

Update table based on value in related table

Posted on 2011-09-26
4
224 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
  • 2
  • 2
4 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you :)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

11 Experts available now in Live!

Get 1:1 Help Now