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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 INSERT INTO

Author  Topic 

programer
Posting Yak Master

221 Posts

Posted - 2010-08-07 : 11:54:20
Hi,

I have this query:

INSERT INTO [Products] ([ProductName], [SupplierID], [CategoryID], [QuantityPerUnit], [UnitPrice], [UnitsInStock], [UnitsOnOrder], [ReorderLevel], [Discontinued]) VALUES (@ProductName, @SupplierID, @CategoryID, @QuantityPerUnit, @UnitPrice, @UnitsInStock, @UnitsOnOrder, @ReorderLevel, @Discontinued);
SELECT ProductID, ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued, (SELECT CategoryName FROM Categories WHERE (CategoryID = Products.CategoryID)) AS CategoryName, (SELECT CompanyName FROM Suppliers WHERE (SupplierID = Products.SupplierID)) AS SupplierName FROM Products WHERE (ProductID = SCOPE_IDENTITY())


This works fine.

I'd like to know how to use "INSERT INTO" 3x the information stored in the same column.

Example:
I've a column "Nickname"

I want to save the data:
programmer
programer2
programer3

My column "Nickname" now looks like this:
programmer
programer2
programer3


Please Help!


slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2010-08-07 : 12:12:31
this will give you some ideas:

create table t_name
(name varchar(10)
,gender tinyint)

insert into t_name
select
x.name + cast(s.number as varchar(2))
,x.gender
from
(
select 'slimt' as name
,1 as gender
) as x
cross join master.dbo.spt_values as s
where s.type = 'P' and s.number in (1,2)

select * from t_name
drop table t_name
Go to Top of Page

programer
Posting Yak Master

221 Posts

Posted - 2010-08-07 : 13:53:34
quote:
Originally posted by slimt_slimt

this will give you some ideas:

create table t_name
(name varchar(10)
,gender tinyint)

insert into t_name
select
x.name + cast(s.number as varchar(2))
,x.gender
from
(
select 'slimt' as name
,1 as gender
) as x
cross join master.dbo.spt_values as s
where s.type = 'P' and s.number in (1,2)

select * from t_name
drop table t_name




thanks!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-08-08 : 02:31:45
you want to insert as a batch? from where you will get three values to be inserted? from another table?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2010-08-08 : 07:39:24
most probably he will get it from another table or this insert statement will be more or less static :)
Go to Top of Page
   

- Advertisement -