SELECT INTO a table variable in T-SQL

Got a complex SELECT query, from which I would like to insert all rows into a table variable, but T-SQL doesn’t allow it. Along the same lines, you cannot use a table variable with SELECT INTO or INSERT EXEC queries. http://odetocode.com/Articles/365.aspx Short example: declare @userData TABLE( name varchar(30) NOT NULL, oldlocation varchar(30) NOT NULL ) … Read more

Insert multiple rows WITHOUT repeating the “INSERT INTO …” part of the statement?

I know I’ve done this before years ago, but I can’t remember the syntax, and I can’t find it anywhere due to pulling up tons of help docs and articles about “bulk imports”. Here’s what I want to do, but the syntax is not exactly right… please, someone who has done this before, help me … Read more

Solutions for INSERT OR UPDATE on SQL Server

Assume a table structure of MyTable(KEY, datafield1, datafield2…). Often I want to either update an existing record, or insert a new record if it doesn’t exist. Essentially: IF (key exists) run update command ELSE run insert command What’s the best performing way to write this? 23 s 23 don’t forget about transactions. Performance is good, … Read more

“INSERT IGNORE” vs “INSERT … ON DUPLICATE KEY UPDATE”

While executing an INSERT statement with many rows, I want to skip duplicate entries that would otherwise cause failure. After some research, my options appear to be the use of either: ON DUPLICATE KEY UPDATE which implies an unnecessary update at some cost, or INSERT IGNORE implies an invitation for other kinds of failure to … Read more

How to insert an element after another element in JavaScript without using a library?

There’s insertBefore() in JavaScript, but how can I insert an element after another element without using jQuery or another library? 19 s 19 referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling); Where referenceNode is the node you want to put newNode after. If referenceNode is the last child within its parent element, that’s fine, because referenceNode.nextSibling will be null and insertBefore … Read more

Inserting multiple rows in a single SQL query? [duplicate]

This question already has answers here: Insert multiple rows WITHOUT repeating the “INSERT INTO …” part of the statement? (16 answers) Closed 8 years ago. I have multiple set of data to insert at once, say 4 rows. My table has three columns: Person, Id and Office. INSERT INTO MyTable VALUES (“John”, 123, “Lloyds Office”); … Read more