>>>>DECLARE @NumberRecords int >>>>DECLARE @RowCount int >>>>DECLARE @Name nvarchar(50) >>>>DECLARE @Company int >>>>DECLARE @Category nvarchar(50) >>>>DECLARE @Subcategory nvarchar(50) >>>>DECLARE @HomePhone int >>>>DECLARE @WorkPhone nvarchar(56) >>>>DECLARE @Extension nvarchar(50) >>>>DECLARE @FaxNumber nvarchar(50) >>>>DECLARE @CellPhone nvarchar(50) >>>>DECLARE @OtherPhone1 nvarchar(50) >>>>DECLARE @OtherPhone2 int >>>>DECLARE @OtherPhone3 int >>>>DECLARE @Street1 nvarchar(50) >>>>DECLARE @CityState nvarchar(50) >>>>DECLARE @ZipCode float >>>>DECLARE @XmasList bit >>>>DECLARE @Srf int >>>>DECLARE @Surfer int >>>>DECLARE @Client int >>>>DECLARE @Directions varchar(250) >>>>DECLARE @Email nvarchar(50) >>>>DECLARE @Email2 nvarchar(50) >>>>DECLARE @WebSite nvarchar(50) >>>>DECLARE @Music int >>>>DECLARE @Played int >>>>DECLARE @Venue int >>>>DECLARE @Notes varchar(250) >>>>DECLARE @Children int >>>>DECLARE @LiquidBlue int >>>>DECLARE @FromTable varchar(8) >>>> >>>> >>>>-- Pull the records into a temp table >>>>SELECT * >>>> INTO #TmpContactInfo1 >>>> FROM ContactInfo1 >>>> >>>>-- Get the number of records in the temporary table and >>>>-- create a counter variable >>>>SET @NumberRecords = @@ROWCOUNT >>>>SET @RowCount = 1 >>>> >>>>-- Loop through all records in the temporary table using the WHILE loop construct >>>>WHILE @RowCount <= @NumberRecords >>>>BEGIN >>>> >>>> SELECT Name = @Name, >>>> Company = @Company, >>>> Category = @Category, >>>> Subcategory = @Subcategory, >>>> HomePhone = @HomePhone, >>>> WorkPhone = @WorkPhone, >>>> Extension = @Extension, >>>> FaxNumber = @FaxNumber, >>>> CellPhone = @CellPhone, >>>> OtherPhone1 = @OtherPhone1, >>>> OtherPhone2 = @OtherPhone2, >>>> OtherPhone3 = @OtherPhone3, >>>> Street1 = @Street1, >>>> CityState = @CityState, >>>> ZipCode = @ZipCode, >>>> XmasList = @XmasList, >>>> Srf = @Srf, >>>> Surfer = @Surfer, >>>> Client = @Client, >>>> Directions = @Directions, >>>> Email = @Email, >>>> Email2 = @Email2, >>>> WebSite = @WebSite, >>>> Music = @Music, >>>> Played = @Played, >>>> Venue = @Venue, >>>> Notes = @Notes, >>>> Children = @Children, >>>> LiquidBlue = @LiquidBlue, >>>> FromTable = @FromTable >>>> FROM #TmpContactInfo1 >>>> WHERE RowID = @RowCount >>>> >>>> SET @RowCount = @RowCount + 1 >>>>END >>>> >>>>DROP TABLE #TmpContactInfo1 >>>>>>>
SELECT ROW_NUMBER() OVER(ORDER BY Name) AS RowId, * INTO #TmpContactInfo1 FROM ContactInfo1