0
Good morning, I have doubts about how to compare a temporary table with a database table. What I want to return is, among all the data of 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]
How the column is declared
BodyShopBusinessId
? There are rows with repeated values of CPNJ, both in the table#TEMP
how much in the tableBodyShop
?– José Diz
So it could be, ?
– Rudolph Mühlbauer