Results 1 to 7 of 7

Thread: Problem with the Following Cursor

  1. #1

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    830

    Question Problem with the Following Cursor

    Good Afternoon All

    I have the Following Cursor



    Code:
    DECLARE VAL_CURSOR CURSOR FOR
    SELECT PROPERTY_ID, NEW_MARKET_VALUE, NEW_ATTRIB_CODE, 
    ACTUAL_EXTENT, GETDATE() AS STATUS_DATE,11 AS VAL_REASON_ID, 6 AS VAL_METHOD_ID
    FROM  PROPERTY_MASS
    WHERE NEW =1 
     
     
    OPEN VAL_CURSOR
    
    DECLARE @PROPERTY_ID INT 
    DECLARE @MARKET_VALUE INT
    DECLARE @NEW_ATTRIB_CODE VARCHAR(12)
    DECLARE @STATUS_DATE DATETIME
    DECLARE @NEW_EXTENT FLOAT 
    DECLARE @VAL_REASON_ID INT
    DECLARE @PAR_METHOD_ID INT
    
    FETCH NEXT FROM VAL_CURSOR INTO
    @PROPERTY_ID,
    @MARKET_VALUE,
    @NEW_ATTRIB_CODE,
    @STATUS_DATE,
    @NEW_EXTENT,
    @VAL_REASON_ID,
    @PAR_METHOD_ID
    
     
    WHILE @@FETCH_STATUS = 0
    BEGIN
    INSERT VALUATION (PROPERTY_ID,NEW_IMPROVED_VALUE,NEW_ATTRIB_CODE,STATUS_DATE,NEW_EXTENT,VAL_REASON_ID,PAR_METHOD_ID)
    VALUES(@PROPERTY_ID, @MARKET_VALUE,@NEW_ATTRIB_CODE,@STATUS_DATE,@NEW_EXTENT,@VAL_REASON_ID,@PAR_METHOD_ID)
     
    FETCH NEXT FROM VAL_CURSOR INTO
    @PROPERTY_ID, @MARKET_VALUE,@NEW_ATTRIB_CODE,@STATUS_DATE,@NEW_EXTENT,@VAL_REASON_ID,@PAR_METHOD_ID
    END
     
    CLOSE VAL_CURSOR
    DEALLOCATE VAL_CURSOR
    when i run it gives me the Following Error

    Msg 16922, Level 16, State 1, Line 26
    Cursor Fetch: Implicit conversion from data type datetime to float is not allowed.
    .
    What is Wrong

    Thanks
    Last edited by vuyiswamb; Jun 2nd, 2008 at 07:22 AM.

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Problem with the Following Cursor

    Put this in a query window and see what prints

    Code:
    DECLARE VAL_CURSOR CURSOR FOR
    SELECT PROPERTY_ID, NEW_MARKET_VALUE, NEW_ATTRIB_CODE, 
    ACTUAL_EXTENT,11 AS VAL_REASON_ID, 6 AS VAL_METHOD_ID
    FROM  PROPERTY_MASS
    WHERE NEW =1 
    
    OPEN VAL_CURSOR
    
    DECLARE @PROPERTY_ID INT 
    DECLARE @MARKET_VALUE INT
    DECLARE @NEW_ATTRIB_CODE VARCHAR(12)
    DECLARE @STATUS_DATE VARCHAR(100)  -- Note: change datatype here
    DECLARE @ACTUAL_EXTENT FLOAT 
    DECLARE @VAL_REASON_ID INT
    DECLARE @PAR_METHOD_ID INT
    
    SET @STATUS_DATE = GETDATE()
    
    FETCH NEXT FROM VAL_CURSOR INTO
    @PROPERTY_ID, @MARKET_VALUE,@NEW_ATTRIB_CODE,@STATUS_DATE,@VAL_REASON_ID,@PAR_METHOD_ID
    
     
    WHILE @@FETCH_STATUS = 0
    BEGIN
    
    IF ISDATE(@STATUS_DATE)=0 PRINT CAST(@PROPERTY_ID AS CHAR(20))+'"'+@STATUS_DATE+'"'
    
    FETCH NEXT FROM VAL_CURSOR INTO
    @PROPERTY_ID, @MARKET_VALUE,@NEW_ATTRIB_CODE,@STATUS_DATE,@VAL_REASON_ID,@PAR_METHOD_ID
    END
     
    CLOSE VAL_CURSOR
    DEALLOCATE VAL_CURSOR
    btw - why are you using a CURSOR instead of

    INSERT INTO VALUATION SELECT PROPERTY_ID...FROM PROPERTY_MASS WHERE...
    Last edited by szlamany; Jun 2nd, 2008 at 07:28 AM.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    830

    Question Re: Problem with the Following Cursor

    Thanks for your Reply

    Am Running it from the Query Window and that Error is what it is Complaining about.

    and it points to this line

    FETCH NEXT FROM VAL_CURSOR INTO

    Thanks

  4. #4
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Problem with the Following Cursor

    Did you see the change in the datatype that I posted?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  5. #5

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    830

    Question Re: Problem with the Following Cursor

    Am Sorry about that,

    It Printed me the Following

    Code:
    781652              "17"
    781653              "21"
    781656              "17"
    781658              "17"
    781667              "77"
    781668              "77"
    781671              "90"
    781671              "90"
    781674              "121"
    774032              "154"
    774034              "147"
    Msg 232, Level 16, State 3, Line 28
    Arithmetic overflow error for type int, value = 7153000000.000000.
    Thanks

  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Problem with the Following Cursor

    As you can see from that print out - you have bad values in the date fields.

    17 and 21 are not dates.

    Bad data - can you trace where it came from?

    As for that formatting error - that's another field. You can change one of the INT's to varchar(100) - one at a time - and see exactly which field it is.

    This is no way to be scrubbing data - what is the data source?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  7. #7

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    830

    Resolved Re: Problem with the Following Cursor

    Good Evening thanks it worked Fine

    i have Adjusted the datatype from the Source table to the Destination Table

    thanks you are a Star

Posting Permissions

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



Click Here to Expand Forum to Full Width