SQL Where In not finding values I know exist

198 Views Asked by At

I work in a school district that uses Powerschool, and Powerschool has a custom report system that allows users to enter in SQL queries directly. When I use the custom report :

SELECT T.DCID, T.LastFirst, T.teachernumber, T.Users_DCID
FROM TEACHERS T 
WHERE T.STATUS=1 and T.SCHOOLID=~(curschoolid)
ORDER BY T.LAST_NAME ASC, T.FIRST_NAME ASC

I get a populated table like this:

DCID    lastfirst   teachernumber   users_dcid

5433    -------------   216335  5433
7855    -------------   216430  7855
7576    -------------   216376  7576
26021   -------------   7365739166  9748

But when I modify my query to add in selecting for certain data:

SELECT T.DCID, T.LastFirst, T.teachernumber, T.Users_DCID
FROM TEACHERS T 
WHERE T.teachernumber IN (216335, 216430, 7365739166) and T.STATUS=1 and T.SCHOOLID=~(curschoolid)
ORDER BY T.LAST_NAME ASC, T.FIRST_NAME ASC

The output is:

No data available in table

I've looked up the documentation and t.teachernumber is a string(20). So I tried adding CONVERT(string(20), 216335) to the WHERE IN () but that still came up with nothing.

What is wrong withy my query?

2

There are 2 best solutions below

0
Hogan On

You want this:

WHERE T.teachernumber IN ('216335', '216430', '7365739166') -- etc

String constants use single quotes

0
ℛɑƒæĿᴿᴹᴿ On
SELECT T.DCID, T.LastFirst, T.teachernumber, T.Users_DCID FROM TEACHERS T 
       WHERE T.teachernumber IN ('216335', '216430', '7365739166') 
             AND T.STATUS=1 AND T.SCHOOLID=~(curschoolid)
ORDER BY T.LAST_NAME ASC, T.FIRST_NAME ASC