Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
bbauer1973
Starting Member
3 Posts |
Posted - 2010-04-14 : 12:02:10
|
| I am trying to create a payroll application and I would like to take the data from one table and insert it into another with almost the same schema. The first table is basically STORED PAYROLL DETAILS and the second is PAYROLL DETAILS. Basically the STORED DETAILS table will store a list of personnel and related data that is reoccurring on a daily payroll so that the user doesn't have to enter the data everyday. The difference between the two tables is that the DETAILS table has a foreign key of PAYROLL_ID needing to match the PAYROLL table. I tried to write a statement in which I pass the PAYROLL ID from .net control via a parameter like so:INSERT INTO payroll_details (payroll_id, name, worker_id, job_category)SELECT FROM payroll_details_stored (@payroll_id, name, worker_id, job_category)This obviously doesn not work as the parameter is passed form the page and is not selected from the STORED table. Thanks in advance for any help on the correct syntax. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
bbauer1973
Starting Member
3 Posts |
Posted - 2010-04-14 : 12:17:51
|
| Sorry...I am using that format exactly as you state:INSERT INTO payroll_details (payroll_id, name, worker_id, job_category)SELECT @payroll_id, name, worker_id, job_categoryFROM payroll_details_storedBut it states that the scalar varibale @parameter is not defined |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2010-04-14 : 13:39:09
|
| Well you need to handle the parameter in your .NET code then. I can show you how it's done in T-SQL, but it's different from .NET:DECLARE @payroll_id intSET @payroll_id = 999INSERT INTO payroll_details (payroll_id, name, worker_id, job_category)SELECT @payroll_id, name, worker_id, job_categoryFROM payroll_details_storedSo the next step for you is to figure out how to do that same thing from within .NET.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
bbauer1973
Starting Member
3 Posts |
Posted - 2010-04-14 : 15:15:44
|
| It works! Thanks! |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|
|
|