Solved

SQL server query

Posted on 2016-09-28
2
56 Views
Last Modified: 2016-09-28
I have the following query, it works fine but need to extend it a little

The query looks at strshort and where the clients share the same strshort description it returns the rows (essentially its matching client codes)

There are some exceptions in this case its "XC90 VOR PREMIUM" it will never get into the rows as that client used an abbreviation of VOR. to fix that I created a new table called TblShortDescLink
Ive manually made the links in this table by making strcommon
exampleI would like to include the strshort from the third table where a.strshort =thirdtable.strcommon

I am not sure how to do that.

use Dictionary
SELECT a.Strshort, a.ClientName, a.ClientCode
FROM TblWords A
JOIN TblWords B
            ON A.StrShort = B.StrShort
                  AND A.ClientName <> B.ClientName
where a.Strshort like'xc90%Ocean%' --and a.ClientName='Smmt'

group by a.Strshort, a.ClientName, a.ClientCode
order by a.StrShort, a.ClientName, a.ClientCode

Open in new window

query output
0
Comment
Question by:PeterBaileyUk
2 Comments
 
LVL 47

Expert Comment

by:Vitor Montalvão
ID: 41819299
Can you post the expected result?
0
 
LVL 33

Accepted Solution

by:
ste5an earned 500 total points
ID: 41819301
The question is: Why want you to include that third table?

E.g.
SELECT  A.Strshort ,
        A.ClientName ,
        A.ClientCode
FROM    TblWords A
WHERE   A.Strshort LIKE 'xc90%Ocean%'
        AND EXISTS ( SELECT *
                     FROM   TblWords B
                     WHERE  A.StrShort = B.StrShort
                            AND A.ClientName <> B.ClientName )
        AND EXISTS ( SELECT *
                     FROM   thirdtable C
                     WHERE  A.StrShort = C.strcommon )
ORDER BY A.StrShort ,
        A.ClientName ,
        A.ClientCode;

Open in new window

0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

825 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