May 19, 2008 at 8:39 pm
Hi Sql gurus,
HI gurus,
DECLARE @int_counter AS INT
OPEN c_table
FETCH NEXT FROM c_table INTO @int_counter
WHILE @@fetch_status = 0
BEGIN
UPDATE student
SET std_acc ='123456789' + CAST(@int_counter AS VARCHAR(9)),
WHERE std_id = @int_counter ;
SET @int_counter = @int_counter + 1 ;
FETCH NEXT FROM c_table INTO @int_counter
END
CLOSE c_table
DEALLOCATE c_table
the std_acc which is varachar datatype 9 character length. Using above cast it is also adding id characters to std_ACC FIELD so it coming as 123456789123 HOW TO RESTRIRCT STD_ACC FIELD to output as 123456789
Thanks in advance
May 19, 2008 at 8:50 pm
LEFT(std_acc, 9)
But why are you adding characters onto a 9 character field if you only want it to be 9 characters?
And why are you using a cursor for this?
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
May 19, 2008 at 9:32 pm
Hi RBarry ! Thanks for your quick response I'm not clear on your response I'm trying to replicate field for test data
May 20, 2008 at 3:33 am
SET std_acc ='123456789' + CAST(@int_counter AS VARCHAR(9)),
this is the problem, why are you combining the data, if you state in your post that you don't want to?
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply