Advertisement

05.16.2008 at 03:14PM PDT, ID: 23409898
[x]
Attachment Details

Using a "cursor" in Stored Procedure

Asked by hpsuser in MS SQL Server

Tags: Microsoft, SQL Server, 2000

Hello,

I would like to write some SQL that loops thru the results of a SELECT statement.  As an example, if I have a table DEPT with column NAME, I'm guessing the code would look something like below, however I can't get the syntax to work correctly?  Thanks

DECLARE @dept_name varchar(20)

for @dept_name in (select NAME from DEPT)
    print @dept_name
nextStart Free Trial
[+][-]05.16.2008 at 03:19PM PDT, ID: 21586901

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Tags: Microsoft, SQL Server, 2000
Sign Up Now!
Solution Provided By: angelIII
Participating Experts: 2
Solution Grade: A
 
 
[+][-]05.16.2008 at 03:21PM PDT, ID: 21586913

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.16.2008 at 03:43PM PDT, ID: 21587009

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628