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)
 Unable to obtain a value

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-11-08 : 08:19:25
rashid writes "hi all,
i am trying to convert a table (Phone) containing the customercode and phone number to a single record table(CustPhoneList)
The phone table has a customer has many phone numbers. the problem is that i get null values in my phoneno column but the code column is ok.
The print statement is does not show any values.
any pointers?
thanks in advance

DECLARE @Code Integer, @OldCode Integer, @Phone Char(10), @CustPhone Varchar(100), @Type Char(3)

Declare TelCursor scroll cursor for Select Code, Number, Type from Phone Order By Code For Read Only
Open TelCursor Fetch TelCursor Into @Code, @Phone, @Type
SET @OldCode = @Code
While @@fetch_status = 0
Begin
If @OldCode = @Code
Begin
SET @CustPhone = @CustPhone + (@Type + ' '+LTRIM(RTRIM(@Phone)) )
PRINT space(10)+@CustPhone
End
ELSE
Begin
Print @CustPhone
INSERT CustPhoneList (Code,PhoneNo) values (@Code,@CustPhone)
SET @OldCode = @Code
SET @CustPhone = Null
SET @CustPhone = @CustPhone +( @Type + ' '+LTRIM(RTRIM(@Phone)) )
End
Fetch TelCursor Into @Code, @Phone, @Type
End
Close TelCursor
Deallocate TelCursor
SELECT * FROM custphonelist"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2004-11-08 : 08:25:17
quote:
any pointers?
Yes. The current design you have is perfect, don't even bother trying to convert it to the new format.
Go to Top of Page
   

- Advertisement -