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
 SQL Server Development (2000)
 Sql Statement is not working

Author  Topic 

Rita Bhatnagar
Posting Yak Master

172 Posts

Posted - 2002-03-15 : 12:21:48
We have two tables from two databases.One table has state abbreviation in it but stateid column is null.
I need to get the stateid for that abbreviation and fill my first table.Second table is state table which has id and abbreviation both.
First table has id column too.
The table update only one row(last one that has id=3).After 3 the loop is breaking.
If i do 'Select @id,@StateID,@State'
I get all three records.
Any Suggestion would be appreciated.


Declare @id int
Declare @State nvarchar(10)
Declare @StateId int
Set @id=1
While @id <= (select Max(id) from tblImplementSchedule)
Begin
Set @State=(select state from tblImplementSchedule where id=@id)




Set @StateId=(select StateID from hhtbusinessCenter.dbo.smlstate
where hhtbusinessCenter.dbo.smlstate.abbreviation=(Select @State))

Update tblImplementSchedule
Set StateID=(Select @StateID)

--Select @id,@StateID,@State

Set @id=@id+1
If @id =4
Break
End

Rita Bhatnagar
Posting Yak Master

172 Posts

Posted - 2002-03-15 : 12:34:24
Found the answer
The update statement had some problem
I put like this

Update tblImplementSchedule
Set StateId=(Select @StateID) where
State=@State

Go to Top of Page
   

- Advertisement -