Skip to Content
author's profile photo Former Member
Former Member

problem in inserting values to userfields

hi

i am facing problem when i am inserting values in to ueser fields . for inserting code and name i am auto incrementing those values . up to 10 records i am getting fine but the value is not incrementing to 11 and i am not getting any error or exception. i am unable to understand the problem . is there any configuration for that can anyone help me regarding this concept .if any configuration how to do that . i am accessing B1 database using DIAPI.

regards

om prakash

Add comment
10|10000 characters needed characters exceeded

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Aug 01, 2006 at 01:56 PM

    Hi Om Prakesh,

    The problem you are having is that the code is a string field which SQL reads like an alpha. If you have codes from 1 to 10, it reckons the maximum is 9! Because it sorts it as follows: 1,10,2,3,4,5,6,7,8,9. So this query

    select max(code) + 1 from [@mytable]

    will return 10, even if 10 is already there. you need to convert your code to a numeric when running the query, like:

    select max(convert(int, code)) + 1 from [@mytable]

    Hope it helps,

    Adele

    Add comment
    10|10000 characters needed characters exceeded