Advertisement

06.23.2008 at 12:30PM PDT, ID: 23508784
[x]
Attachment Details

SqL Statement

Asked by lulu50 in MS SQL DTS, MS SQL Server, MySQL

Tags: SQL 2000

Hi,
I have this store procedure.  where I first created a Merge temp table.  filled the table with data then I get the MaxNum the count.  I am having problem with do while loop I want to say while the MaxNum <= totaltexaco update the temp table
so if the Maxnum is 50 I want to update the temp table and set the internalid with numbers start with 51 up to the count number for all the records in the tables.

Create Procedure dbo.ChevronTexacoMerge As

Declare @MaxNum as int
Declare @CountTexaco as int

Set NoCount On

Create Table #MergeTemp
(
MergeId int IDENTITY PRIMARY KEY,
ExternalID varchar(20),
InternalID int,
ChCustomerID varchar(20),
IVRPin int,
SystemDate smalldatetime
)

--Fill the Mergetemp table with texaco data only
--This will get all ExternalID from Texaco that do not
--have any match with chevron.
Insert Into #TempTable
(
InternalID,
ChCustomerID,
IVRPin,
SystemDate,
ExternalID
)
SELECT dbo_ExternalPointerReference1.InternalID, dbo_ExternalPointerReference1.ChCustomerID, dbo_ExternalPointerReference1.IVRPin, dbo_ExternalPointerReference1.SystemDate, dbo_ExternalPointerReference1.ExternalID
FROM dbo_ExternalPointerReference1
WHERE (((dbo_ExternalPointerReference1.ExternalID) Not In (select dbo_ExternalPointerReference.ExternalID from dbo_ExternalPointerReference)));

--GET the highest InternalID number from the chevron table.
Set @MaxNum = (SELECT Max([InternalID]) AS [Max]
FROM dbo_ExternalPointerReference;) + 1

--Get the count of texaco data in the temptable.
Set @CountTexaco = SELECT Count([ExternalID]) AS ExternalIDCount
FROM #MergeTemp;

   Set @TotalTexaco = @MaxNum + @CountTexaco

--say @MaxNum is 50
--say @CountTexaco is 10
--say @TotalTexaco is 60

Begin            
--here I want to fill InternalId with a number larger than @MaxNum up to the CounTexaco so 51-60 starting from the first record to the end.            
      Do While (@MaxNum <= @TotalTexaco)
            update #MergeTemp set InternalID= @MaxNum = @MaxNum + 1
            where MergeId = @i = @i + 1
   Loop
            
End
Start Free Trial
[+][-]06.23.2008 at 12:32PM PDT, ID: 21849502

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.24.2008 at 01:22AM PDT, ID: 21853352

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MS SQL DTS, MS SQL Server, MySQL
Tags: SQL 2000
Sign Up Now!
Solution Provided By: VMontalvao
Participating Experts: 1
Solution Grade: B
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628