It's sort of like cfloop


DECLARE @myColumn VARCHAR(400)


DECLARE csrLoop CURSOR
FOR
SELECT myColumn
FROM myTable


OPEN csrLoop
FETCH NEXT FROM csrLoop
INTO @myColumn


WHILE @@FETCH_STATUS = 0
BEGIN


    -- do with @myColumn whatever you need to here


    FETCH NEXT FROM csrLoop
    INTO @myColumn
END


CLOSE csrLoop
DEALLOCATE csrLoop


I just wrote in this email so there might be some mistakes (not sure)
The FOR SELECT is what the cursor will loop over


Between the BEGIN and END is where you perform your actions.
Hope that helps, but yes, the books online will make it clearer.


Taco Fleur
Blog  <http://www.tacofleur.com/index/blog/>
http://www.tacofleur.com/index/blog/
Methodology http://www.tacofleur.com/index/methodology/

Tell me and I will forget
Show me and I will remember
Teach me and I will learn

-----Original Message-----
From: Mickael [mailto:[EMAIL PROTECTED]
Sent: Friday, 13 February 2004 11:51 PM
To: CF-Talk
Subject: Re: OT- Sort of Loop in SQL

What are cursors?  Could you show me some sample code?
  ----- Original Message -----
  From: MILAN MUSHRAN
  To: CF-Talk
  Sent: Friday, February 13, 2004 8:30 AM
  Subject: RE: OT- Sort of Loop in SQL

  You can use cursors.

  >From: "Mickael" <[EMAIL PROTECTED]>
  >Reply-To: [EMAIL PROTECTED]
  >To: CF-Talk <[EMAIL PROTECTED]>
  >Subject: OT- Sort of Loop in SQL
  >Date: Fri, 13 Feb 2004 08:23:04 -0500
  >
  >Hi All,
  >
  >I know how complete the following task in CF and SQL but I was wondering
if
  >there is a way to do it with only SQL.  What I am trying to do is modify
  >records sequentially in my database.
  >
  >I have a field in my database called destination, this is an office
  >location.  And I have many records in my database that I would like to
  >assign 1/3 of the records to each of the three offices.  I don't want to
  >just do an update top (then 1/3) and set the office to each of the office

  >ids.  I was wondering if there is a way in SQL to update the first record

  >to the first office ID, then the second record to the second office id,
  >then the third to the third office id, then the forth record to the first

  >office id and continue that way.
  >
  >Is this possible in SQL?  There are Network security issues that won't
let
  >me connect to this database with CF.
  >
  >Mike
  >
  >
  >
  _____
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to