May 5, 2008 at 1:31 am
Dear Experts,
I want to create 1 Million row on the fly without using Cursor or While loop. How ?
Inputs are welcome !
karthik
May 5, 2008 at 2:28 am
Cross join a couple of system tables together. Jeff usually uses spt_values (in master)
You could use a user table also. All you need is one table of 1000 rows.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
May 5, 2008 at 2:39 am
I don't want to use any tables ( including spt_values or Tally table). How to acheive it ?
karthik
May 5, 2008 at 2:46 am
On 2005, you could use a recursive CTE.
Why can't you use a table?
If you absolutely want to do this the hard way, something kinda like this will probably work(partial query only)
SELECT * FROM
(SELECT 1 AS ID
UNION ALL
SELECT 2 AS ID
UNION ALL
... Up to 10... ) virtualTable1
CROSS JOIN
(SELECT 1 AS ID
UNION ALL
SELECT 2 AS ID
UNION ALL
... Up to 10... ) virtualTable2
CROSS JOIN
... Repeat a couple more times until you have enough rows
I doubt this will be particuarly fast, and it will likely impact TempDB badly.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
May 5, 2008 at 2:56 am
I am using sql2000.
Can you give me the full query ?
karthik
May 5, 2008 at 3:10 am
karthikeyan (5/5/2008)
Can you give me the full query ?
You should be able to figure it out.
I don't have time to type out 6 subqueries each with 10 unioned queries in it.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
May 5, 2008 at 3:34 am
Ok.I will try it out.
karthik
Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply