Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 T_sql problem

Author  Topic 

hong_ma
Starting Member

37 Posts

Posted - 2006-02-10 : 14:13:06
Declare @F_ID int
DECLARE @CNT INT

SET @CNT = 1

while @CNT <5
Begin

SELECT @F_ID= [EntityID]
FROM [FACT].[dbo].[adReportingRequirement]

SET @CNT = @CNT + 1

print @F_ID

end

after runing, only print one value four time. why not is four different value?

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2006-02-10 : 14:37:05
You have no WHERE clause in your statement so the value of @f_id is being calculated 4 times each with the same result.

Be One with the Optimizer
TG
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-02-10 : 14:37:43
Because the value of @F_ID is not modified in your code. You need to add a WHERE clause to your query that reflects @CNT's changing value.

SELECT @F_ID= [EntityID]
FROM [FACT].[dbo].[adReportingRequirement]
WHERE SomeColumn = @CNT

Tara Kizer
aka tduggan
Go to Top of Page

hong_ma
Starting Member

37 Posts

Posted - 2006-02-10 : 14:44:47
Thanks you guys. I got it
Go to Top of Page
   

- Advertisement -