Tuesday, February 5, 2008

Script for Inserting setup data

--struc_no_match_tbl has list of tables that have structural changes between PeopleSoft 8 and 9 -- This script creates insert statement for inserting setup data from PeopleSoft 8 database to 9.
DECLARE @TBLNM VARCHAR(50)
DECLARE C2 CURSOR FOR
SELECT RECNAME FROM SVD9..STRUC_NO_MATCH_TBL
OPEN C2
FETCH NEXT FROM C2 INTO @TBLNM
WHILE @@FETCH_STATUS = 0
BEGIN
DECLARE @FN VARCHAR(30),@CL VARCHAR(8000),@SL VARCHAR(8000),@CNTR INT ,@FT INT

Declare C1 CURSOR for SELECT FIELDNAME FROM PSRECFIELDALL WHERE RECNAME = @TBLNM
OPEN C1
FETCH NEXT FROM C1 INTO @FN
SELECT @CL = ' '
SELECT @SL = ' '
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @CNTR = COUNT(*) FROM UCP83..PSRECFIELDALL WHERE RECNAME = @TBLNM AND FIELDNAME = @FN;
SELECT @FT = FIELDTYPE FROM PSDBFIELD WHERE FIELDNAME = @FN
SELECT @CL = @CL + @FN +',';
IF (@CNTR<>1)
IF @FT <> 2
SELECT @SL =@SL + ''' '''+','
ELSE
SELECT @SL = @SL +CHAR(0)+','
else
SELECT @SL = @SL + @FN + ',';
FETCH NEXT FROM C1 INTO @FN
END;
SELECT @CL =SUBSTRING(@CL,1,LEN(@CL)-1)
SELECT @SL =SUBSTRING(@SL,1,LEN(@SL)-1)


PRINT 'INSERT INTO PS_'+@TBLNM +'('+@CL+')'+'SELECT '+ @SL +' FROM '+'UCP83..PS_'+@TBLNM

CLOSE C1
DEALLOCATE C1

FETCH NEXT FROM C2 INTO @TBLNM
END;

CLOSE C2
DEALLOCATE C2

No comments: