Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

In VB - Format(value,"0000000") - how to do it in SQL? 2

Status
Not open for further replies.

suoirotciv

Programmer
Dec 3, 2002
205
0
0
PH

declare @cCustNo as varchar(20), @nType as numeric
declare @vTelNo as numeric

DECLARE RS_cursor CURSOR
FOR
SELECT cCustomerNo, nType FROM Customer_Contact
OPEN RS_cursor
FETCH NEXT FROM RS_cursor INTO @cCustNo, @nType

set @vTelNo = 0

while @@FETCH_STATUS = 0
begin
set @vTelNo = @vTelNo + 1


update Customer_Contact set cTelNo = cast(@vTelNo as varchar(7)) where cCustomerNo = @cCustNo and nType = @nTYpe

FETCH NEXT FROM RS_cursor INTO @cCustNo, @nType
end

close RS_cursor

========================================================
but this will just simply update the value to 1 to end of recordset

i need it to be formatted to "0000001", "0000002" . . . etc . .

could any help me on this please . . .


Please pardon the grammar.
Not good in english.
 
see REPLICATE and LEN...

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
that's nice . . . i use the code below

REPLICATE('0', 7 - LEN(@vTelNo)) + @vTelNo

thanks a lot . . .

Please pardon the grammar.
Not good in english.
 
That was great StoneDeCroze . . .

Two heads are really better than one . . .

Please pardon the grammar.
Not good in english.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top