Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating table based on Select query in stored procedure / ColdFusion
    primarykey
    data
    text
    <p>I am using ColdFusion for for a project and I have a written a query which I think can be faster using a stored procedure, but I not a T-SQL person, so I am not sure how to do it to compare.</p> <p>I am running an initial query which selects a number of fields from a table based on a dynamically built cfquery. I think I know how to convert this query into the SQL Server stored procedure. </p> <p>However, directly after that, I then take all of the primary key IDs from that query and run another query against a separate table that "locks" records with those IDs. The lock is a bit field (a flag) in the second table that tells the system that this record is "checked out". I have wrapped both queries in a <code>cftransaction</code> so that they execute as a unit.</p> <p>Code Overview:</p> <pre><code>&lt;cftransaction&gt; &lt;cfquery name="selectQuery"&gt; SELECT id, field2, field3 FROM table1 WHERE (bunch of conditions here) &lt;/cfquery&gt; &lt;cfquery name="updateQuery"&gt; UPDATE table2 SET lockField = 1 WHERE table2.id IN (#ValueList(selectQuery.id#) &lt;/cfquery&gt; &lt;/cftransaction&gt; </code></pre> <p>I then return the selectQuery resultset to my app which uses it for outputting some data. How would I accomplish the same thing in a single SQL Server 2008 stored procedure that I could call using <code>cfstoredproc</code>? </p> <p>Again, I am thinking that the native CF way (with <code>cfquery</code>) is not as efficient as a stored procedure since I have to retrieve the resultset back to CF, then call another query back to the DB. A single stored procedure does everything in the DB and then returns the original query resultset for use.</p> <p>Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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