Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Scan of table
Message
General information
Forum:
Microsoft SQL Server
Category:
Other
Title:
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01312331
Message ID:
01312862
Views:
17
>Sorry for double post, I tried your code and it worked fine until it reached the last record in my test set- where it then loops - this is my modified code
>
>
>Create Procedure DontUseCursors
>As
>DECLARE @MasterRef varchar(10)
>DECLARE @ClaimRef varchar(10)
>
>
>Declare @i int
>
>SELECT @MasterRef = c.MasterRef,
>       @ClaimRef = p.ClaimRef
> FROM PIFTest p
>	Inner Join claim c
>	on c.ClaimRef = p.ClaimRef
>      INNER JOIN (SELECT MIN(ClaimRef) AS ClaimRef FROM PIFTest) Tbl1
>ON p.ClaimRef = Tbl1.ClaimRef
>
>Select @i = Count(ClaimRef) From PIFTest
>
>WHILE (@i > 0)
>    BEGIN
>	print @ClaimRef
>       SELECT @MasterRef = c.MasterRef,
>       @ClaimRef = p.ClaimRef
> 	FROM PIFTest p
>		Inner Join claim c
>		on c.ClaimRef = p.ClaimRef
>     	 INNER JOIN (SELECT MIN(ClaimRef) As ClaimRef FROM PIFTest
>	 Where ClaimRef > @ClaimRef) Tbl1
>	ON p.ClaimRef = Tbl1.ClaimRef
>	print @i
>	Set @i = (@i - 1)
>    END
>
>
>GO
>
>
>In this example I'm only printing out the variable, if I leave the While condition as "While @ClaimRef is not null" it just loops so I changed it to what you see ( which is not exactly elegant - but it works ) it seems @ClaimRef is never null - thanks




Sorry for late answer, but was too busy to do anything but read.
Why you use two tables when you need just one?
You could get both fields from ClaimRef table, isn't it?
Create Procedure DontUseCursors
As
DECLARE @MasterRef    varchar(10)
DECLARE @MasterRefMax varchar(10)
DECLARE @ClaimRef     varchar(10)


Declare @i int

SELECT @MasterRef    = c.MasterRef,
       @MasterRefMax = Tbl1.MaxRef,
       @ClaimRef     = c.ClaimRef
 FROM claim c
      INNER JOIN (SELECT MIN(ClaimRef) AS ClaimRef, MAX(ClaimRef) AS MaxRef FROM Claim) Tbl1
ON c.ClaimRef = Tbl1.ClaimRef

WHILE @MasterRef IS NOT NULL AND @MasterRef <= @MasterRefMax
    BEGIN
       print @ClaimRef
       SELECT @MasterRef = c.MasterRef,
              @ClaimRef  = c.ClaimRef
 	FROM claim c
        INNER JOIN (SELECT MIN(ClaimRef) As ClaimRef FROM claim
                           Where ClaimRef > @ClaimRef) Tbl1
	ON p.ClaimRef = Tbl1.ClaimRef
    END
again not tested :-)
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform