Note that there are some explanatory texts on larger screens.

plurals
  1. POReconciling a column across two tables in SQL Server
    text
    copied!<p>There are two Databases, Database A has a table A with columns of id, group and flag. Database B has a table B with columns of ID and flag. Table B is essentially a subset of table A <code>where the group == 'B'</code>. </p> <p>They are updated/created in odd ways that are outside my understanding at this time, and are beyond the scope of this question (this is not the time to fix the basic setup and practices of this client). </p> <p>The problem is that when the flag in Table A is updated, it is not reflected in table B, but should be. This is not a time-critical problem, so it was suggested I create a job to handle this. Maybe because it's the end of the week, or maybe because I've never written more than the most basic stored procedure (I'm a programmer, not a DBA), but I'm not sure how to go about this.</p> <p>At a simplistic level, the stored procedure would be something along of the lines of</p> <pre><code>Select * in table A where group == B </code></pre> <p>Then, loop through the <code>resultset</code>, and for each id, update the flag.</p> <p>But I'm not even sure how to loop in a <code>stored procedure</code> like this. Suggestions? Example code would be preferred.</p> <p><strong>Complication:</strong> Alright, this gets a little harder too. For every group, Table B is in a separate database, and we need to update this flag for all groups. So, we would have to set up a separate trigger for each group to handle each DB name.</p> <p>And yes, inserts to Table B are already handled - this is just to update flag status.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload