I think I can do this with a case statement, however, I am not 100% sure of the syntax or how to do this.
What I have done so far is created a temp table with all the fields I need. I have 20 user defined fields that I need to export as a single record from a 1-many relationship.
I started doing this with a cursor, but there has to be a better way.
Would there be a way to do this from the intial insert? or through a single pudate?
What I have done so far is created a temp table with all the fields I need. I have 20 user defined fields that I need to export as a single record from a 1-many relationship.
I started doing this with a cursor, but there has to be a better way.
Code:
Create table #test
PROIDNO VARCHAR(20),
PROUD01 varchar(30),
PROUD02 varchar(20),
PROUD03 varchar(10),
PROUD04 varchar(50)
INSERT INTO TEST (proidno) select PROIDNO FROM TABLE PROJECT
Declare @proidno varchar(30),
@empid varchar(20),
@role varchar(10),
@desc varchar(50)
declare pro1 cursor for select distinct proidno, employee, role, [description] from
dbo.cfgemployeerole, dbo.emprojectassoc
where dbocfgemployeerole.code = dbo.emprojectassoc.role
order by proidno
open pro1
fetch next from pro1 into
@proidno,
@empid,
@role,
@desc
while @@fetch_status = 0
begin
If @role = 'a' then
update #test set PROUD01 = @EMPID where proidno = @proidno
else
if @role = b then
update #test set PROUD02 = @EMPID where proidno = @proidno
END
fetch next from pro1 into
@proidno,
@empid,
@role,
@desc
end
Would there be a way to do this from the intial insert? or through a single pudate?