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.
| 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:programmerprogramer2programer3My column "Nickname" now looks like this:programmerprogramer2programer3Please 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_nameselectx.name + cast(s.number as varchar(2)),x.genderfrom(select 'slimt' as name ,1 as gender) as xcross join master.dbo.spt_values as swhere s.type = 'P' and s.number in (1,2)select * from t_namedrop table t_name |
 |
|
|
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_nameselectx.name + cast(s.number as varchar(2)),x.genderfrom(select 'slimt' as name ,1 as gender) as xcross join master.dbo.spt_values as swhere s.type = 'P' and s.number in (1,2)select * from t_namedrop table t_name
thanks! |
 |
|
|
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 MVPhttp://visakhm.blogspot.com/ |
 |
|
|
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 :) |
 |
|
|
|
|
|
|
|