Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Silly question (regarding insert)

Author  Topic 

kashyap_sql
Posting Yak Master

174 Posts

Posted - 2010-09-30 : 01:56:55
how can i insert bulk values at a time
ex:- i had a table custid and the table consists of single column i,e custid 1 to 100
table
i want to insert all the values at time how can it be done

With Regards
Kashyap M

EugeneLim11
Posting Yak Master

167 Posts

Posted - 2010-09-30 : 03:17:45
Declare @count int
Set @count = 0
while @count < 100
begin
Insert into Custid (custid) values (@count)
@count = @count + 1
end
GO
Go to Top of Page

kashyap_sql
Posting Yak Master

174 Posts

Posted - 2010-09-30 : 03:24:33
thanks EugeneLim11 for your reply but it is showing a error @count

With Regards
Kashyap M
Go to Top of Page

EugeneLim11
Posting Yak Master

167 Posts

Posted - 2010-09-30 : 03:28:42
Oops. Forget to use the word SET



Declare @count int
Set @count = 1
while @count < 101
begin
Insert into Custid (custid) values (@count)
Set @count = @count + 1
end
GO

Go to Top of Page

kashyap_sql
Posting Yak Master

174 Posts

Posted - 2010-09-30 : 03:35:34
that's nice query it works very nicely cheers to YOU

With Regards
Kashyap M
Go to Top of Page

kashyap_sql
Posting Yak Master

174 Posts

Posted - 2010-09-30 : 03:42:26
if you don't mind can i ask you another question that is just i would like to see the result in horizontal view
such as

custid 1. 2. 3. 4. 5. 6. 7. .......100

is it possible ???
plz if you can
With Regards
Kashyap M
Go to Top of Page

lazycoder
Starting Member

12 Posts

Posted - 2010-09-30 : 04:06:24
try this:

declare @res varchar(8000)
SET @res = ''
SELECT @res = @res + ' ' + convert(varchar(50), custid) FROM Custid
SELECT @res
Go to Top of Page

kashyap_sql
Posting Yak Master

174 Posts

Posted - 2010-09-30 : 04:25:47
hey coder the table name is custid and it has a column name is custid and the column has values from 1 to 100 this is the structure of the table

With Regards
Kashyap M
Go to Top of Page

EugeneLim11
Posting Yak Master

167 Posts

Posted - 2010-09-30 : 05:07:48
Are you using MSSQL 2005 or 2008? If so there is a function you may want to try: PIVOT

http://code.msdn.microsoft.com/SQLExamples/Wiki/View.aspx?title=PIVOT Data in SQL 2005&referringTitle=Home

Hope this helps to return the results you want.. :)
Go to Top of Page

kevlangdo
Starting Member

5 Posts

Posted - 2010-09-30 : 05:38:04
You may want to check this out as a way to create dynamic columns from a select to use with PIVOT
http://hubpages.com/hub/t-sqlDynamicCrossTabs

Kevin Languedoc
Sr BI Developer
www.kcodebook.com/wp
Go to Top of Page

NeilG
Aged Yak Warrior

530 Posts

Posted - 2010-09-30 : 06:51:47
pivot function
Go to Top of Page

kashyap_sql
Posting Yak Master

174 Posts

Posted - 2010-10-01 : 00:44:14
sorry for the delay in posting
exactly i am trying to learn about pivoting and i am using sql 2005 server

With Regards
Kashyap M
Go to Top of Page
   

- Advertisement -