Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL server query

Posted on 2016-09-28
2
Medium Priority
?
67 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 52

Expert Comment

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

Accepted Solution

by:
ste5an earned 2000 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

885 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