S.O.S

  • Hi-, I have really weird problem.

    My biz logic request to generate unique id, so the sp gets parametr "type" varchar(3), next this id have to be started with 'A' pls "type" pls random number to fill up the rest in total 9 char.

    Here's the sample of rand() function I'm using to get 5 char number...

    declare @rnd int,

    @Upper int,

    @Lower int

    set @Lower = (DATEPART(ss, GETDATE()) * 1 )

    set @upper = (DATEPART(ms, GETDATE()) * 100 )

    SET @rnd = CAST(((@Upper - @Lower + 1) * RAND() + @Lower) AS Int)..

    after that there is a cast to varchar and len check and concatination all 3 in one that goes to insert. All works fine untill I do isert which works fine when I'm in debugging stand alone mode.

    When I run this sp with real data my id comes out as 'A*'.? Appreciate your ideas!!

    Thnx.

    PS. All happens in .NET SQL2000/SP3

  • I have no issues myself. Can you provide more code to the point of where the A number is finally generated?

  • quote:


    I have no issues myself. Can you provide more code to the point of where the A number is finally generated?

    OK. Here is the rest of it. Hope it helps..

    SET @rnd2 = CAST(@rnd as varchar(5))

    if @type is null

    Begin

    Set @aimid = 'A099' + @rnd2

    Select @len = len(@aimid)

    if @len < 9

    Begin

    if @len = 5

    Set @rnd = @rnd * 10000

    else

    if @len = 6

    Set @rnd = @rnd * 1000

    else

    if @len = 7

    Set @rnd = @rnd * 100

    else

    if @len = 8

    Set @rnd = @rnd * 10

    SET @rnd2 = CAST(@rnd as varchar(5))

    Set @aimid = ''

    Set @aimid = 'A099' + @rnd2


  • OK. I thinh I know what's wrong. The middle string get lost if it hardcoded in concat.

    I passed it as parm and it worked OK.

    Thnx.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply