Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL server query

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

Expert Comment

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

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
I have a large data set and a SSIS package. How can I load this file in multi threading?
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.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

721 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