Solved

SQL server query

Posted on 2016-09-28
2
49 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 46

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

920 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

16 Experts available now in Live!

Get 1:1 Help Now