Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!
Insert into TblSource (oldTableName) Select Name From sys.tables Where type_desc ='USER_TABLE' AND (Name like 'emp%') Declare @ID int , @srcTblName nvarchar(50) , @country varchar(3) , @desTblName varchar(50) , @loopCntr int Set @loopCntr = @@ROWCOUNT While @loopCntr <> 0 Begin Set @ID = ( Select ID From TblSource Where ID = @loopCntr ) Set @srcTblName = ( Select oldTableName From TblSource Where ID = @ID) Set @Country = ( Select Country From tblCountry Where C_Abr = ( CASE substring(@srcTblName,6,2) WHEN 'U' THEN 'US' WHEN 'U' THEN 'UK' END)) Set @desTblName = RIGHT(@srcTblName,LEN(@srcTblName) --don't pay much attention to this formula, imagin it works fine and return correct name. Update TblSource Set Country = @Country , desTblName = @desTblName Where ID = @ID Set @ID = (Select ID From TblSource Where oldTblName = 'employee') set @srcTblName =(Select oldTblName From TblSource Where ID = @ID ) If (@ID <> '') Begin Insert Into @desTblName ( location_ID, [country], [Active]) Select Distinct (s.location) ,@Country 1 From (Select oldTblName From TblSource Where ID = @ID) AS s --@srcTblName -- End End set @loopcntr = @loopcntr -1 END
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.