June 3, 2003 at 7:48 pm
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
June 4, 2003 at 4:27 am
I have no issues myself. Can you provide more code to the point of where the A number is finally generated?
June 4, 2003 at 7:38 am
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
else
if @len = 6
else
if @len = 7
else
if @len = 8
SET @rnd2 = CAST(@rnd as varchar(5))
Set @aimid = ''
Set @aimid = 'A099' + @rnd2
June 4, 2003 at 8:55 am
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