Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Update table based on value in related table

Posted on 2011-09-26
4
Medium Priority
?
237 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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

715 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