?
Solved

Query to look in two columns in a table for the same value

Posted on 2010-11-30
8
Medium Priority
?
281 Views
Last Modified: 2012-05-10
Hello. I have a custom MS SQL 2005 SP3 database used in SCCM 2007 OSD deployments. The database contains a table that has four columns. The columns are computer name, old computer name, mac address and date name was changed.

I am trying to write a query that looks at the values in the computer name column and  the value name in the old computer name column, if the same value is in both colums it outputs it. The value will not be on the same row so I cannot do a match.

For example, I have a machine called Computer1. It is both the computername and oldcomputername columns. I want the query to output all values for both rows that it is in. Is this possible?

Below is my query to pull in everything from the table.

SELECT *
FROM MachineInformation
0
Comment
Question by:Lorrec
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 19

Expert Comment

by:Bhavesh Shah
ID: 34242219
hi,

sory but your Q is not much clear.

SELECT *
FROM MachineInformation
WHERE Computername=oldcomputername

what you want exactly
0
 
LVL 27

Accepted Solution

by:
Shaun Kline earned 2000 total points
ID: 34242305
Sounds like you want something like this:

SELECT *
FROM MachineInformation MI
   INNER JOIN MachineInformation MI_Old ON MI.ComputerName = MI_Old.oldcomputername
0
 
LVL 6

Expert Comment

by:hyphenpipe
ID: 34242555
Or are you looking just for this?

select * from MachineInformation
 where [computer name] = 'Computer1'
 or [old computer name] = 'Computer1'
0
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!

 

Author Comment

by:Lorrec
ID: 34242645
Thanks for the response. Ihat is what I needed.
0
 

Author Closing Comment

by:Lorrec
ID: 34242652
Thank you for the help.
0
 
LVL 19

Expert Comment

by:Bhavesh Shah
ID: 34245125
Hi Shaun.

what is the difference between my query and ur query???
can you please explain??
0
 
LVL 6

Expert Comment

by:hyphenpipe
ID: 34247388
Brichsoft -

Your query would only return rows where both the computername column and oldcomputername matched in the same row.

The inner join Shaun did would return every row in the table where the computername column and oldcomputername matched regardless of if they originally existed in the same row.
0
 
LVL 19

Expert Comment

by:Bhavesh Shah
ID: 34247402
Hey...

Thanks a lot sir.....

somehow,my mind was stop thinking....

Thanks
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

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 SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

864 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