Serial Number Column – SQL Server 2000

Gia su co bang
Emp(emp_code,
emp_name,
emp_address)
create proc SerialNumber
as
create table #tem(
 col0 int,
 col1 varchar(50),
 col2 varchar(50),
 col3 varchar(50)
)

declare @var1 varchar(50)
declare @var2 varchar(50)
declare @var3 varchar(50)
declare @s int
set @s = 0

declare empcur cursor scroll
for select * from emp

open empcur
fetch next from empcur into @var1, @var2,@var3
while @@FETCH_STATUS = 0
begin
 select @s = @s + 1
 insert into #tem values(@s,@var1,@var2,@var3)
 fetch next from empcur into @var1,@var2,@var3
end

close empcur
deallocate empcur

select * from #tem

exec SerialNumber

2 thoughts on “Serial Number Column – SQL Server 2000

  1. Chao Thay
    select ltrim(f1) from table1
    Em dung ham ltrim, nhung not effect, cai truong f1 van chua cac khoang trang. Vay Thay chi cho em cachh cut duoc cac blank nay voi
    Cam on Thay

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s