I have an input from a iothub to a stream analytics(SA). This input contains data detected by a Bluetooth device and I store them on a data base (an output of the SA), in a table called InputMessages. The problem is that I have another table (Devices) with the devices that it must detect. Its primary key is the MAC of the detected devices which is also related with the inputMessages by FK. Sometimes I have an error in the stream analytics input because the detected device is not in the devices table. I'm trying to make a filter on the SA query to avoid this happening discarding the messages from the devices that are not in the Devices table with this code, but its not working.
The query looks like this:
IF EXISTS(
SELECT deviceId
FROM inputSqlDevices D, inputIotHub M
WHERE D.deviceId= M.deviceId') BEGIN
SELECT
Message
INTO
outputsql
FROM
inputiothub
WHERE
END
Any suggestion?