Solved

sql server query

Posted on 2016-08-15
2
32 Views
Last Modified: 2016-08-15
I have a query just for demonstration, I need to create a query that tells me where strshort matches but the client is different its all in one table so I am not sure how to create that.

My feeble attempt after looking at microsoft site
SELECT StrShort1.StrShort, StrShort2.ClientName
FROM TblWords.strshort AS StrShort1
     JOIN TblWords.strshort AS StrShort2
       ON (StrShort1.strshort = StrShort2.strshort)
WHERE StrShort1.clientName <>StrShort1.clientName;

Open in new window



<TblWords StrShort="V70 XL" ClientName="Abi" />
<TblWords StrShort="V70 XL" ClientName="Cap" />
<TblWords StrShort="V70 XL" ClientName="Glass" />
<TblWords StrShort="V70 XL" ClientName="Smmt" />

the above would present as a match as strshort is all the same but with different clients

<TblWords StrShort="V70 XL 10V" ClientName="Abi" />
<TblWords StrShort="V70 XL 10V" ClientName="Smmt" />

the above would present as a match as strshort is all the same but with different clients

<TblWords StrShort="V70 XL" ClientName="Smmt" />
<TblWords StrShort="V70 XL 10V" ClientName="Abi" />

the above dont match as strshort is different.

use Dictionary
select StrShort, ClientName
from TblWords
where StrShort like'v70%xl%'
group by StrShort,  ClientName

Open in new window

0
Comment
Question by:PeterBaileyUk
2 Comments
 
LVL 8

Accepted Solution

by:
Randy Peterson earned 500 total points
ID: 41756611
Try this:

SELECT *
FROM TblWords A
JOIN TblWords B
            ON A.StrShort = B.StrShort
                  AND A.ClientName <> B.ClientName
0
 

Author Closing Comment

by:PeterBaileyUk
ID: 41756660
Thank you
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

706 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

18 Experts available now in Live!

Get 1:1 Help Now