Link to home
Start Free TrialLog in
Avatar of jverasql
jverasql

asked on

Sql Script to loop through results insert copies of each record and update title name ending in -A for example to -B, -C etc.

Need assistance with a SQL Script.  Below are three sql statements. Would I need three scripts or one to loop through and complete the task in bold.  How would I do this?  I understand looping but do not know the variables that are needed and how to set up loops.

select * from DMRepository where tiRecordStatus=1 and chUpdateBy='aukathyw' and vchDocName like '%NEW%- A'-- insert each result of multiple records 10 times to same table  and update -A to -B, -C .... to-K --for example this query returns 50 results each result would be inserted 10 times so 500 records would be inserted in total

select * from DMRepository where tiRecordStatus=1 and chUpdateBy='aukathyw' and vchDocName like '%Used%- M'-- insert each result of multiple records  4 times to same table and update-M to -N, -O ...to -Q

select * from DMRepository where tiRecordStatus=1 and chUpdateBy='aukathyw' and vchDocName not  like '%NEW%' and vchDocName not  like '%Used%'--insert each result of multiple records  15 times to same table and update-A to -B, -C .... to -Q


Below are the insert statements I have been working on,
this   insert each result of multiple records 10 times to same table  and update -A to -B, -C .... to-K

insert into DMRepository (iSiteId,vchDocName,iDocTypeId,vchSubject,vchReply, vchMimeType,chUser,txtLitContent,iContentSize, iEmailType,iFaxType,iPrintType,tiRecordStatus,chUpdateBy,dtUpdateDate,iSurveyId,iAutoType,iTrackingEmail,DMRepositoryDocumentSourceId,OemLocked)
select iSiteId,vchDocName,iDocTypeId,vchMimeType,chUser,txtLitContent,iContentSize, iEmailType,iFaxType,iPrintType,tiRecordStatus,chUpdateBy,dtUpdateDate,iSurveyId,iAutoType,iTrackingEmail,DMRepositoryDocumentSourceId,OemLocked
from DMRepository where tiRecordStatus=1 and chUpdateBy='aukathyw' and vchDocName  like '%NEW%- A'

this  insert each result of multiple records  4 times to same table and update-M to -N, -O ...to -Q
insert into DMRepository (iSiteId,vchDocName,iDocTypeId,vchSubject,vchReply, vchMimeType,chUser,txtLitContent,iContentSize, iEmailType,iFaxType,iPrintType,tiRecordStatus,chUpdateBy,dtUpdateDate,iSurveyId,iAutoType,iTrackingEmail,DMRepositoryDocumentSourceId,OemLocked)
select iSiteId,vchDocName,iDocTypeId,vchMimeType,chUser,txtLitContent,iContentSize, iEmailType,iFaxType,iPrintType,tiRecordStatus,chUpdateBy,dtUpdateDate,iSurveyId,iAutoType,iTrackingEmail,DMRepositoryDocumentSourceId,OemLocked
from DMRepository where tiRecordStatus=1 and chUpdateBy='aukathyw' and vchDocName  like '%Used%- M'like '%Used%- M'


this insert each result of multiple records  15 times to same table and update-A to -B, -C .... to -Q
insert into DMRepository (iSiteId,vchDocName,iDocTypeId,vchSubject,vchReply, vchMimeType,chUser,txtLitContent,iContentSize, iEmailType,iFaxType,iPrintType,tiRecordStatus,chUpdateBy,dtUpdateDate,iSurveyId,iAutoType,iTrackingEmail,DMRepositoryDocumentSourceId,OemLocked)
select iSiteId,vchDocName,iDocTypeId,vchMimeType,chUser,txtLitContent,iContentSize, iEmailType,iFaxType,iPrintType,tiRecordStatus,chUpdateBy,dtUpdateDate,iSurveyId,iAutoType,iTrackingEmail,DMRepositoryDocumentSourceId,OemLocked
from DMRepository where tiRecordStatus=1 and chUpdateBy='aukathyw' and vchDocName  not  like '%NEW%' and vchDocName not  like '%Used%'
ASKER CERTIFIED SOLUTION
Avatar of jverasql
jverasql

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial