Solved

select into same table syntax

Posted on 2006-06-23
2
198 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 24

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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Suggested Solutions

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now