|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
||||
|
||||
|
cursors filling table
looking for some help on a stored procedure. here is what i have. it is supposed to insert the unique values from an existing table into a new table. should be 40, but instead it continually puts in blank values and won't stop. so here's the proc.
Code:
CREATE PROCEDURE sp_filltitletable AS declare title_curs cursor for select title from employee group by title for read only declare @actualtitle varchar(50) open title_curs fetch title_curs into @actualtitle while @@fetch_status = 0 begin insert into Emp_Title (Title) values (@actualtitle) end close title_curs deallocate title_curs figured it out, had the fetch in the wrong spot!
__________________
My brain cells are like a storm trooper's armor: useless Last edited by don_sparko : November 10th, 2003 at 09:39 AM. |
|
#2
|
|||
|
|||
|
Using a cursor is unnecessary, all you need is
Code:
insert into Emp_Title (Title) select distinct title from employee |
|
#3
|
||||
|
||||
|
swamp. thanks, maybe you can help me with the next step. here is the table structure so you know what i'm trying to do.
Code:
employee ------------ title titleID fk emp_title -------------- titleID pk title i'm actually fixing the DB here. the unique titles have been taken from employee and put in emp_title. what i want to do now is put the titleID from emp_title into titleID in employee where employee.title = emp_title.title any ideas? |
|
#4
|
|||
|
|||
|
Code:
update employee set titleID = (select titleID from emp_title where title = employee.title) |
|
#5
|
||||
|
||||
|
thanks worked great!
|
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > cursors filling table |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|