Updating In-Memory (Temporary) SQL Tables With UPDATE / DELETE Clauses

<cfquery name="qID" datasource="#REQUEST.DSN.Source#">
	DECLARE
		@id TABLE (
			id1 INT,
			id2 INT
		)
	;
 
 
	<!---
		Populate the in-memory table variable with the
		pivot data. We are going to store the same ID
		into both columns so that we can demonstrate
		that it was updated.
	--->
	INSERT INTO @id
	(
		id1,
		id2
	)(
		SELECT TOP 5
			p.id AS id1,
			p.id AS id2
		FROM
			pivot100 p
	);
 
 
	<!--- Update the in-memory query. --->
	UPDATE
		@id
	SET
		id2 = (id2 + 5)
	;
 
 
	<!--- Delete from the in-memory query. --->
	DELETE FROM
		@id
	WHERE
		id1 >= 4
	;
 
 
	<!--- Select all values from the in-memory table. --->
	SELECT
		*
	FROM
		@id
</cfquery>
 
 
<!--- Dump out the query with both ID columns. --->
<cfdump
	var="#qID#"
	label="ID Query"
	/>

For Cut-and-Paste