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

x
?
Solved

Compare column data

Posted on 2007-04-05
2
Medium Priority
?
196 Views
Last Modified: 2010-03-19
Hi Experts,

Here is my table:
Account (AccountId, UserId, Currency)
                 1                   1            USD
                 2                    1           USD
                 3                    2           EUR
                 4                    1           USD
                 5                    2           USD

I need to compare the currencies because 1 user must only have 1 currency.
So, in my  example, User1 currency is USD (no problem) so I can  return the currency of User1.
But User2 has 2 currencies so I need to throw an  error.

Thanks in advance for your help.
                 
0
Comment
Question by:noulouk
[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 Comments
 
LVL 5

Assisted Solution

by:Yttribium
Yttribium earned 600 total points
ID: 18856814
Why not have the User Table contain the Currency, and join it to this Account table?

Like
TABLE: [User]
ID
Name
Currency

TABLE [Account]
AccountID
UserID


VIEW AccountCurrency
SELECT     Account.AccountID, Account.UserID, User.Currency
FROM         Account INNER JOIN
                      User ON Account.UserID = User.UserID
0
 
LVL 6

Accepted Solution

by:
chiragkhabaria earned 1400 total points
ID: 18856940
Something like this

PS Not i have added some records in the table for more testing...

The query will return all the user name whoese has more then one currency in the Currency column...



-- Create the Table Varaible for checking..
Declare @Account Table
(
      AccountId int,
      UserId int,
      Currency varchar(10)
)

-- Insert the Values in the TAble VAraible for testing.
Insert @Account
 Select 1,1, 'USD' Union All
Select 2, 1,'USD' Union All
Select 3, 2,'EUR' Union All
Select 4, 1,'USD' Union All
Select 6, 2,'USD' Union All
Select 7, 1,'EUR' Union All
Select 8, 3,'USD' Union All
Select 9, 3,'USD' Union All
Select 10, 4 ,'USD' Union All
Select 11, 4,'EUR'


-- Now this is the query which will extract the duplicate records

Select Distinct UserID  From @Account a
Where UserID In
(
      Select  UserID From @Account b where a.UserID = b.UserID And a.Currency <> b.Currency
)

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

730 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