Results 1 to 4 of 4

Thread: Cursor to Array

  1. #1
    Join Date
    Oct 2003
    Location
    Arkansas
    Posts
    15

    Unanswered: Cursor to Array

    Can you Assign a cursor to an array

    For example:

    Declare AuditInfo cursor
    for
    Select top 2 TRAKRID,MeterID,DelCount,ContactID,Type,Active,Cre atedDateTime,ModifiedBy,DateModified
    from TRAKRAudit
    where TRAKRID = @ID
    order by createdDatetime desc
    --Print @ID
    open AuditInfo

    -- Get all the newest values
    fetch next From AuditInfo into Array()

    Thanks
    LJ
    Hope is the feeling that the feeling that you have will not last very long.

  2. #2
    Join Date
    Sep 2003
    Posts
    522
    Code:
    declare @tbl table (...)
    insert @tbl Select top 2 TRAKRID,MeterID,DelCount,ContactID,Type,Active,Cre
    atedDateTime,ModifiedBy,DateModified
    from TRAKRAudit 
    where TRAKRID = @ID
    order by createdDatetime desc

  3. #3
    Join Date
    Oct 2003
    Location
    Arkansas
    Posts
    15
    Ok this leads me to another ?

    Is there any way to dynamically go through the columns in this Temp table.

    The 2 records represent Old and New Values from Table1 and Table1_audit.

    I am building a string:

    Select @NewStr = Coalesce(convert(varchar(25),@MeterIDNew),'null')
    Select @NewStr = ('New MeterID = ' + @NewStr)
    Select @OldStr = Coalesce(convert(varchar(25),@MeterIDOld),'null')
    Select @OldStr = ('Old Meter ID = ' + @OldStr)
    Select @StrOutput = @StrOutput + @NewStr + @OldStr + Char(10)

    Select @NewStr = Coalesce(convert(varchar(25),@MV90IDNew),'null')
    Select @NewStr = ('New MV90 ID = ' + @NewStr)
    Select @OldStr = Coalesce(convert(varchar(25),@MV90IDOld),'null')
    Select @OldStr = ('Old MV90 ID = ' + @OldStr)
    Select @StrOutput = @StrOutput + @NewStr + @OldStr + Char(10)
    .
    .
    .

    To put in the body of an e-mail.

    Sample
    ---------------------------------------------------------------------------
    New SCADA ID = 58 Old SCADA ID = 58
    New MeterID = null Old Meter ID = null
    New MV90 ID = Entergy Old Meter ID = Entergy
    New Name = TestNamejon Old Name = TestNamejon
    --------------------------------------------------------------------------------

    I need to do this for 10 tables. I am looking for a way to do this programitaclly so I do not have to create a stored procedure for each of these Tables. And if the table def changes I do not have to change the SP.

    Thanks for the speedy reply
    LJ
    Hope is the feeling that the feeling that you have will not last very long.

  4. #4
    Join Date
    Sep 2003
    Posts
    212
    try gettin the names of the table from sysobjects (usign a cursor) and make generic code for ur process which will use the tablenames from the names in sysobject.

    so u can do sumthin for as many tables as u want. with just one sp

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •