Format SQL - valid but incorrect sql
KevinGreiner
Posts: 37 Bronze 3
I found a scenario today where Format SQL will change the SQL statement shown below into valid SQL that runs without error but is wrong. This is a dangerous error because the SQL is changed in a way that results in no UPDATE actually happening.
The UPDATE is changed to
CREATE TABLE Cars (name VARCHAR(10) ,wheels INT); CREATE TABLE c (name VARCHAR(10)); UPDATE r3 SET r3.wheels = c.wheels FROM dbo.Cars r3 CROSS APPLY (SELECT wheels = 4) c;
The UPDATE is changed to
UPDATE r3 SET r3.wheels = r3.wheels FROM dbo.Cars r3 CROSS APPLY (SELECT wheels = 4) c;
Comments
I tried this with the latest version but I couldn't reproduce the behaviour you described. Can you try upgrading to the latest version to see if that fixes things? The URL is here if you need it - ftp://support.red-gate.com/patches/SQLP ... .0.335.exe
Redgate Software
Looking through my original post, I see that I missed two steps. First, execute just the first two statements. Then refresh your suggestions.
Now you should be able to reformat the UPDATE code shown and see the incorrect result.
I've been able to reproduce the problem and have filed a bug report with reference SP-5246. I don't have a timeframe for a possible fix, but I'll let you know when I hear any information.
Thanks for letting us know about the bug.
Redgate Software
This should now be fixed in the latest beta release.
Redgate Software