title: Microsoft SQL Server, selecting an id and inserting into another table
body: <p>I have this code for inserting some rows into the following table - and i am getting the id from another table that is already populated. Using Compact 4.0 Local Database Here with C# and Razor.</p>
  
  <p>get id from sortedWord table:</p>
  
  <pre><code>Id | SortedWord
  0    act
  </code></pre>
  
  <p>insert data into words table:</p>
  
  <pre><code>Id | Word | SortedId
  0    cat    0
  1    tac    0
  
      for (var i = 0; i &lt; words.Count(); i++){
          queryString = "SELECT Id FROM SortedWords WHERE SortedWord = @0";
          var sortedId = db.QuerySingle(queryString, sortWord(words[i]));
          queryString = "INSERT INTO Words (Word, SortedId) VALUES (@0, @1)";
          db.Query(queryString, words[i], sortedId.Id);
      }
  </code></pre>
  
  <p>Trouble is the select statement is inefficient, is it possible to do this without a select statement, something like select into: I saw some examples here but cant make sense of it.
  <a href="http://technet.microsoft.com/en-us/library/ms189872(v=sql.105).aspx" rel="nofollow">http://technet.microsoft.com/en-us/library/ms189872(v=sql.105).aspx</a> </p>