MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old November 10th, 2003, 09:15 AM
don_sparko's Avatar
don_sparko don_sparko is offline
Digitally Challenged
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 280 don_sparko User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 14 sec
Reputation Power: 6
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.

Reply With Quote
  #2  
Old November 10th, 2003, 09:50 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,766 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 6 h 24 m 8 sec
Reputation Power: 37
Using a cursor is unnecessary, all you need is

Code:
insert into Emp_Title (Title) 
select distinct title from employee

Reply With Quote
  #3  
Old November 10th, 2003, 11:04 AM
don_sparko's Avatar
don_sparko don_sparko is offline
Digitally Challenged
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 280 don_sparko User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 14 sec
Reputation Power: 6
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?

Reply With Quote
  #4  
Old November 10th, 2003, 11:36 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,766 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 6 h 24 m 8 sec
Reputation Power: 37
Code:
update employee
set titleID = (select titleID
from emp_title 
where title = employee.title)

Reply With Quote
  #5  
Old November 10th, 2003, 12:37 PM
don_sparko's Avatar
don_sparko don_sparko is offline
Digitally Challenged
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 280 don_sparko User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 14 sec
Reputation Power: 6
thanks worked great!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > cursors filling table


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway