September 27, 2012 at 11:41 am
hi
i want to insert 1000 rows in a table without any loop.
how can i do it?
September 27, 2012 at 11:57 am
harri.reddy (9/27/2012)
hii want to insert 1000 rows in a table without any loop.
how can i do it?
Start with the first link in my signature.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 β Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
September 27, 2012 at 4:35 pm
;with a
as
(
select 1 a
union select 2
union select 3
union select 4
union select 5
union select 6
union select 7
union select 8
union select 9
union select 10
)
SELECT a
INTO #t
FROM a a1 cross join a a2 cross join a a3
September 28, 2012 at 1:59 am
You can do like this also
INSERT INTO Tablename( COLUMNName )
VALUES ( 0 ),(1),(2)......(1000)
September 28, 2012 at 2:03 am
harri.reddy (9/27/2012)
hii want to insert 1000 rows in a table without any loop.
how can i do it?
In what format are the 1000 rows?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
September 28, 2012 at 9:29 am
justmohit (9/28/2012)
You can do like this alsoINSERT INTO Tablename( COLUMNName )
VALUES ( 0 ),(1),(2)......(1000)
That is really funny π
Do you want a query which will build this kind of statement dynamically or you prefer to type it in? :hehe:
September 28, 2012 at 10:06 am
Or you could try this undocumented procedure.
exec Insert1000RowsInATableWithoutAnyLoop
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 β Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
September 28, 2012 at 11:14 am
Try selecting approximately 1000 from rows from other table (if you have any) and then do .../
INSERT INTO TESTTABLE(Col1)
SELECT Tcol1 FROM OTHER TABLE WHERE .....
If you need this for any specific purpose, please provide the details..........
September 28, 2012 at 2:47 pm
Try this. Given at least 1000 records exist in tblTest, this would insert 1000 rows into temporary table tblTemp.
SELECT column1 INTO #tblTemp
FROM tblTest
WHERE column1 IN
(SELECT TOP 1000 [col1]
FROM tblTest)
September 28, 2012 at 8:36 pm
These are the kinds of interview questions that I ask to find out how much a person may know about set based programming.
Please see the following article for multiple answers to your question. If you actually study the article, it will change your career for the better... seriously.
[font="Arial Black"]The "Numbers" or "Tally" Table: What it is and how it replaces a loop.[/font][/url]
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply