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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Inserting values into a table from within sp.

Author  Topic 

eastcoaster
Starting Member

17 Posts

Posted - 2006-08-09 : 22:08:43
Want to write a stored procedure and open a cursor, validate data and insert values from source to target table.
One of the values inserted will be a concatination of various columns from source, ie.,

substring(employee_name,1,1) + coalesce(employee_DOB,'')

Any help on where to start is appreciated.

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-08-09 : 22:13:00
What is it that you don't know how to do?




CODO ERGO SUM
Go to Top of Page

nosepicker
Constraint Violating Yak Guru

366 Posts

Posted - 2006-08-10 : 00:16:26
Sample data, table structures, and desired results please.
Go to Top of Page

eastcoaster
Starting Member

17 Posts

Posted - 2006-08-11 : 19:55:35
Source table – Employee
Employee_id int,
Employee_name char(50),
Employee_DOB char(10)

Target Table – Employee_bck
Employee_id int,
Employee_name_DOB char(60)

I want to open a cursor to parse Employee table and insert values into Employee_bck table. However, I want to put Employee_name and Employee_DOB together and insert it into Employee_name_DOB.

Thnx.

quote:
Originally posted by nosepicker

Sample data, table structures, and desired results please.


Go to Top of Page

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2006-08-11 : 21:46:59
There is no need for a cursor. There is almost never a need for a cursor.

Update b
Set b.Employee_Name_Dob = a.Employee_name + a.Employee_DOB
from Employee a inner join Employee_bck b
on a.EmployeeID = b.EmployeeID
Go to Top of Page

nosepicker
Constraint Violating Yak Guru

366 Posts

Posted - 2006-08-11 : 23:06:11
Or, if you want to insert new records (based on your original post):

INSERT INTO Employee_bck (Employee_id, Employee_name_DOB)
SELECT Employee_id, SUBSTRING(Employee_name, 1, 1) + ISNULL(Employee_DOB, '')
FROM Employee
Go to Top of Page
   

- Advertisement -