Solved

Compare column data

Posted on 2007-04-05
2
191 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 150 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 350 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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
Error when saving to sql table a '/' 5 32
Replace Dates in query 14 58
How do I subtract date and time within a same column in SQL 4 56
date diff with Fiscal Calendar 4 86
This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
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 an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

710 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