Good morning, I have questions on how to perform a comparison between a temporary table and a database table. What I want to return is, among all the data in the temporary table, it returns the ones I have in the database (null) and the ones I do not have in the database.
IF OBJECT_ID('TEMPDB.DBO.#TEMP') IS NOT NULL
DROP TABLE #TEMP
CREATE TABLE #TEMP (
CODIGO VARCHAR(100)
)
...
...
INSERT INTO #TEMP VALUES ('20023275000158')
INSERT INTO #TEMP VALUES ('20023275000158')
UPDATE #TEMP SET CODIGO = '00' + CODIGO WHERE LEN(CODIGO) = 13 -- adiciona 00 antes do número
UPDATE #TEMP SET CODIGO = '0' + CODIGO WHERE LEN(CODIGO) = 14
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
SELECT DISTINCT [cbs].[BodyShopId] [Oficina],
[cbs].[BodyShopBusinessId] [CNPJ],
[cbs].[AdditionalData].value('(/AdditionalDataForBodyShop/IsDiamond[1]', 'BIT' ) [OficinaDiamante],
[t].[CODIGO]
FROM #TEMP t
LEFT JOIN [Country].[BodyShop] [cbs]
ON [t].CODIGO = [cbs].[BodyShopBusinessId]
--WHERE [cbs].[AdditionalData].value('(/AdditionalDataForBodyShop/IsDiamond)[1]', 'BIT' ) = 1
order by [Oficina]