August 1, 2002 at 11:42 am
hello,
I have a table with repeating groups
ie
user_name
puller
stocker
data_entry
verifier
I want to normilize the table and put the different job types into job_type table. Is it possible to do this with one SQL statement
currently I'm using several ie
insert into job_type
select puller
from users
where puller = 1
thanks for any help
August 1, 2002 at 11:51 am
If puller is the information you want to insert, you could do the following:
INSERT INTO job_type
SELECT DISTINCT
puller
FROM users
K. Brian Kelley
http://www.sqlservercentral.com/columnists/bkelley/
K. Brian Kelley
@kbriankelley
August 1, 2002 at 12:40 pm
WHAT I WANT TO DO IS MOVE THE INFORMATION IN
PULLER,
VERIFIER,
DATA_ENTRY
STOCKER,
INTO THE WORK_TYPE TABLE WITH ONE QUERY
August 1, 2002 at 1:41 pm
Can you post the CREATE TABLE statements for both tables and a handful of records?
K. Brian Kelley
http://www.sqlservercentral.com/columnists/bkelley/
K. Brian Kelley
@kbriankelley
August 2, 2002 at 1:30 am
You could use a construct like the following, extending the UNION subquery to all the different types.
select p1.user_name, case p2.type when 1 then 'Puller' when 2 then 'Stocker' end
from persons p1,
(select user_name, 1 as type from persons where puller = 1
UNION
select user_name, 2 as type from persons where stocker = 1) p2
where p1.user_name = p2.user_name
Maybe someone can come up with a cleaner solution.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply