SQL query join

Posted on 2011-05-11
Last Modified: 2012-05-11
I would like to pull these two tables together to I can list by date what tests were given, and also display the name of the test given.

 Table: CompanyTests Table: Tests
Question by:rrhandle8
    LVL 32

    Expert Comment

    if the test ids are always three characters, you can join using charindex

    select companytest.*, tests.*
    from companytests
    inner join tests on charindex(cast(tid as varchar), tests) > 0
    LVL 32

    Accepted Solution


    select companytest.*, tests.*
    from companytests
    inner join tests on charindex(cast(tests.tid as varchar), companytest.tests) > 0
    LVL 51

    Assisted Solution

    to be on safe side:

    select companytest.*, tests.*
    from companytests
    inner join tests on charindex(',' + cast(tests.tid as varchar) + ',', ',' + companytest.tests +',') > 0

    this will search ",700," in ",700,701,720,721,"

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
    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.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    728 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

    20 Experts available now in Live!

    Get 1:1 Help Now