Solved

select into same table syntax

Posted on 2006-06-23
2
225 Views
Last Modified: 2008-03-03
Hi,
I'm wondering if there is a way to select rows that match a criteria and copy back into the same table.
All copied data would be the same as the original except for 2 columns which would then be specified.
thanks
0
Comment
Question by:dgrafx
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 16968461
Something like:

    INSERT INTO YourTable (FirstName, LastName, Age)  SELECT FirstName, 'Smith', Age FROM YourTable;

Will select FirstName and Age from YourTable, but will give each copied record a value of "Smith" for LastName.
0
 
LVL 25

Author Comment

by:dgrafx
ID: 16968536
I don't even know what I'm talking about.
Got confused asking this question ...
What I was doing was selecting from table a certain criteria -
then I did an insert query using data from first query going row by row -
knew this seemed inefficient ..
I'm on my first cup of coffee - rough night ...
As soon as I read your response I said "Idiot!"
I just need to insert and select using the criteria from the first query - eliminating the first query altogether.
easy as cake
thanks for pointing this out and I won't post again until I'm on second cup (of coffee)
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SharePoint 2013/ SQL 2014 - content database backup and restore from Prod to Dev 10 38
SSMS Opening Mode 9 20
RESTORE MASTER DATABASE -- NOW 2 20
SQL Recursion 6 20
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question