SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 leading zero and how to create temporary table
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kabon
Starting Member

Indonesia
40 Posts

Posted - 06/18/2012 :  04:30:37  Show Profile  Reply with Quote
Excuse me,

I want to ask how to display like this using leading zero:
1000001
1000002
1000003
1000004
1000005
1000006
1000007
1000008
1000009
1000010
1000011

I have the code but can't show the answer like that, this is my code:

declare @startrange int, @ID int
set @startrange = 0

while @startrange <= 10
BEGIN

set @ID = '1' + RIGHT('00000000'+CONVERT(varchar,@startrange),10)
PRINT @ID
set @startrange = @startrange + 1
END
GO

Can you help me?



And last, I want to know how to create temporary table and how to use it?

thanks...

khtan
In (Som, Ni, Yak)

Singapore
16745 Posts

Posted - 06/18/2012 :  04:38:33  Show Profile  Reply with Quote

declare	@startrange	int

select	@startrange = 1

; with 
rcte as
(
	select	ID = @startrange

	union all

	select	ID = ID + 1
	from	rcte
	where	ID	<= 10
)
select	100000000 + ID
from	rcte



KH
Time is always against us

Go to Top of Page

kabon
Starting Member

Indonesia
40 Posts

Posted - 06/18/2012 :  23:43:21  Show Profile  Reply with Quote
If I change where ID <= 110, why this code error?

how about using temporary table and how to use it to cleared this problem?

help me,please....
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
16745 Posts

Posted - 06/19/2012 :  00:00:46  Show Profile  Reply with Quote
it is a recursive CTE. The default value for MAXRECURSION is 100

Specify the maxrecursion value or 0 for no limit.

FROM    rcte
OPTION (MAXRECURSION 1000);



KH
Time is always against us

Go to Top of Page

kabon
Starting Member

Indonesia
40 Posts

Posted - 06/19/2012 :  02:35:19  Show Profile  Reply with Quote
ehm, it's error.
where I must place that code?


Msg 156, Level 15, State 1, Line 16
Incorrect syntax near the keyword 'OPTION'.
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
16745 Posts

Posted - 06/19/2012 :  02:42:44  Show Profile  Reply with Quote
quote:
Originally posted by kabon

ehm, it's error.
where I must place that code?


I have already shown that in my post on 06/19/2012 : 00:00:46


KH
Time is always against us

Go to Top of Page

kabon
Starting Member

Indonesia
40 Posts

Posted - 06/19/2012 :  23:14:22  Show Profile  Reply with Quote
I had replace select ID = ID + 1
from rcte
where ID <= 10


to select ID = ID + 1
FROM rcte
OPTION (MAXRECURSION 1000);
where ID <= 10

but it always appear error that incorrect near OPTION
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
16745 Posts

Posted - 06/19/2012 :  23:19:04  Show Profile  Reply with Quote

declare	@startrange	int

select	@startrange = 1

; with 
rcte as
(
	select	ID = @startrange

	union all

	select	ID = ID + 1
	from	rcte
	where	ID	<= 110
)
select	100000000 + ID
from	rcte
OPTION (MAXRECURSION 1000);



KH
Time is always against us

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000