sql - Error in handling Cursor -



sql - Error in handling Cursor -

code:

declare c cursor select name [trial].[dbo].[student] declare @name varchar(20) set @name = '' open c fetch c @name close c select @name

could 1 help me solving error:

msg 207, level 16, state 1, line 1 invalid column name 'name'.

your cursor usage, illustration give, pulling (random) row student table. functionally equivalent following:

declare @name varchar(20) select @name = select top 1 sname trial.dbo.student

if you're using cursor, syntax should more this:

declare c cursor select sname trial.dbo.student open c fetch next c @name while @@fetch_status = 0 begin /* work involving @name */ /* fetch next row cursor */ fetch next c @name end close c deallocate c

you'll need do work in loop, of course, unless trying pull (random) row pupil table.

sql sql-server tsql sql-server-2008

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -