473,387 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to copy a row

Hi

i want to copy a row and insert that same values in different/same table..

for example

Empno LunchAllovance
1001 50
1002 50

here lunch allovance is 50 for all the employees. i want to copy that and paste as a new record for a new employee. The employee number should be changed.... can anyone help me in this please

Thanks
May 15 '07 #1
4 35562
pradeep kaltari
102 Expert 100+
Hi

i want to copy a row and insert that same values in different/same table..

for example

Empno LunchAllovance
1001 50
1002 50

here lunch allovance is 50 for all the employees. i want to copy that and paste as a new record for a new employee. The employee number should be changed.... can anyone help me in this please

Thanks
Hi,
1: If the lunchAllowance is same for all the employees then you can set a default value to this column and exclude this column from the insert statement.
2: You can insert all the other column(s) in the table except the LunchAllowance. The insert statement should be followed by an UPDATE statement which looks somehing like the following:
Expand|Select|Wrap|Line Numbers
  1. UPDATE EMPLOYEE 
  2. SET LunchAllowance= SELECT DISTINCT(LunchAllowance)
  3.                                   FROM EMPLOYEE
  4. WHERE Empno=<empno_recently_inserted>
  5.  
I hope this answers your question.

Regards,
Pradeep
May 15 '07 #2
Motoma
3,237 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO targetTable (field1, field2) (SELECT field1, field2 FROM sourceTable WHERE condition=check)
  2.  
May 15 '07 #3
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO targetTable (field1, field2) (SELECT field1, field2 FROM sourceTable WHERE condition=check)
  2.  


Thanks for the reply!!!
May 16 '07 #4
Motoma
3,237 Expert 2GB
You are welcome! I hope things work out for you; don't hesitate to come back and ask more questions!


Thanks for the reply!!!
May 16 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

42
by: Edward Diener | last post by:
Coming from the C++ world I can not understand the reason why copy constructors are not used in the .NET framework. A copy constructor creates an object from a copy of another object of the same...
15
by: A | last post by:
Hi, A default copy constructor is created for you when you don't specify one yourself. In such case, the default copy constructor will simply do a bitwise copy for primitives (including...
2
by: Alex | last post by:
Entering the following in the Python shell yields >>> help(dict.copy) Help on method_descriptor: copy(...) D.copy() -> a shallow copy of D >>>
24
by: rdc02271 | last post by:
Hello! Is this too crazy or not? Copy constructor: why can't I copy objects as if they were structs? I have a set of simple objects (no string properties, just integers, doubles) and I have to...
10
by: utab | last post by:
Dear all, So passing and returning a class object is the time when to include the definition of the copy constructor into the class definition. But if we don't call by value or return by value, ...
22
by: clicwar | last post by:
A simple program with operator overloading and copy constructor: #include <iostream> #include <string> using namespace std; class Vector { private: float x,y; public: Vector(float u, float...
3
by: maheshkadam | last post by:
Hi friends I am new to perl so please guide me. I have one application which created backup log file every day.But it appends that file so you can see logs for different day in one file only. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.