troubleshooting Question

T-SQL: How to Pull from One Query Based on Another Query

Avatar of Software Engineer
Software Engineer asked on
ProgrammingSQL* T-SQLMicrosoft SQL ServerProgramming Languages-Other
1 Comment1 Solution52 ViewsLast Modified:
Hi There:

Below is my code.  This code is returning no results, because its subquery is not returning any results.

I know for certain that the subquery should be pulling data and, therefore, returning results.  Yes, the main "idea" is to return LOTs that resemble Components.

When I say "resemble", let me give you an example.  506N is a Component, while 506N418G06A-40 is a LOT.  So, I want the subquery to pull 506N418G06A-40 and therefore the full query to display 506N418G06A-40 and other lots that begin with "506N" as results.

Is there something wrong with the syntax of the subquery?  Do I need to add syntax for "trimming" strings or something along those lines?

Thanks!

Software Engineer

SELECT DISTINCT [LOT]
FROM WIPTEST
INNER JOIN IV30200 ON WIPTEST.[INVHDRBATCH] = IV30200.BACHNUMB
AND WIPTEST.[INVHDRDOC] = IV30200.DOCNUMBR
WHERE [FG] = '506'
  AND [FGBATCH] = '50418G12D'
  AND [INVHDRBATCH] = '50418G12D'
  AND EXISTS
    (SELECT DISTINCT [LOT]
     FROM WIPTEST
     WHERE 
	   [LOT] LIKE [Component]+'%')

Open in new window

ASKER CERTIFIED SOLUTION
lcohan
Database Analyst
Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 1 Comment.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 1 Comment.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004