I have an issue while updating a table variable. I've already declared it, however when I run the whole query I get this error:
Incorrect syntax near '.'.
And I can't seem to solve the issue...
UPDATE @List
SET nrID = CASE
WHEN nrID IS NULL
THEN t1.nrID
ELSE nrID
END
FROM @List
INNER JOIN table1 t1 ON @List.PNr = t1.PNr
INNER JOIN table2 t2 ON t1.n nrPNr = t2.nrPNr
WHERE t1.PNr = t2.PNr AND t2.Isactive = 0
UPDATE List
SET List.nrID = t1.nrID
FROM @List AS List
INNER JOIN table1 t1 ON List.nrID = t1.nrID
INNER JOIN table2 t2 ON t1.nrID = t2.nrID
WHERE t1.nrID = t2.nrID AND t2.Isactive = 0
As mentioned in the comments the inner join will remove any nulls in your case
Thanks for the help, changed my declared @table to create @temptable and it took away my incorrect syntax error.
As for the query I Used (example);
UPDATE Person
SET Car = ISNULL(@Car, Car),
HairColour = ISNULL(@HairColour, HairColour),
Try this,
UPDATE L
SET L.nrID = ISNULL(t1.nrID, t2.nrID)
FROM @List L
INNER JOIN table1 t1 ON L.PNr = t1.PNr
INNER JOIN table2 t2 ON t1.nrPNr = t2.nrPNr
WHERE t1.PNr = t2.PNr
AND t2.Isactive = 0
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.