HoustonGuy
Programmer
I feel like I have a lot of code that could definitely be written better.
Here is one example:
I have 20 fields that need updating from a temp table (#Final) that has a numeric counter field (MyCount).
Currently I have 20 sets of updates for each field.
THis looks sloppy to me. I feel that I should be able to easily iterate a single update statement through a number variable that loops from 1 to 20. But i don't think Field+@variableCOunter will work without writing dynamic code. Dunno. The fact that the field number must match the mycount number throws a kink it in it.
Lastly, i program in a bubble a lot. (NO interaction with other programmers for best practice discussions.) Is there a site that lets you look for alternatives to the code. Something where I could get suggestions to replace update statements?
i'm probably not describing that well.
Thank you in advance!!!
Here is one example:
I have 20 fields that need updating from a temp table (#Final) that has a numeric counter field (MyCount).
Currently I have 20 sets of updates for each field.
SQL:
UPDATE MainTable
SET Field1
FROM #Final A
JOIN MasterTable B
ON A.IDnum = B.IDnum
WHERE A.Mycount = 1
UPDATE MainTable
SET Field2
FROM #Final A
JOIN MasterTable B
ON A.IDnum = B.IDnum
WHERE A.Mycount = 2
UPDATE MainTable
SET Field3
FROM #Final A
JOIN MasterTable B
ON A.IDnum = B.IDnum
WHERE A.Mycount = 3
etc...
THis looks sloppy to me. I feel that I should be able to easily iterate a single update statement through a number variable that loops from 1 to 20. But i don't think Field+@variableCOunter will work without writing dynamic code. Dunno. The fact that the field number must match the mycount number throws a kink it in it.
Lastly, i program in a bubble a lot. (NO interaction with other programmers for best practice discussions.) Is there a site that lets you look for alternatives to the code. Something where I could get suggestions to replace update statements?
i'm probably not describing that well.
Thank you in advance!!!