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 2000 Forums
 Transact-SQL (2000)
 Move serveral rows of data to new table

Author  Topic 

azwiefel
Starting Member

7 Posts

Posted - 2003-08-27 : 22:57:29
I am having trouble with a TSQL query, I need to move several rows of data to another table with in the database, the first table is for reference or baseline data for the second table, I've reveiwed this and other websites, and reveiwed multiples of books. I have figured out a brute way to accomplish this... essentally count the rows of data in the first table and doing a hodge podge select and insert... it has it's issues....

anyone got a solution of a SQL toddler?

Thanks in advanve...

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-08-27 : 23:01:22
insert into table2 (f1,f2,f3)
select f1,f2,f3
from table1
where <some criteria>



- Jeff
Go to Top of Page

azwiefel
Starting Member

7 Posts

Posted - 2003-08-27 : 23:10:14
Thanks... I knew I was being a bozo...
Go to Top of Page

azwiefel
Starting Member

7 Posts

Posted - 2003-08-27 : 23:23:07
An Additional Question...

Ok the following writes table one information to table 2, at the same time from am ASPX web page I have an order ID number that is associated with each inserted row, is there a way I can write it inline with the INSERT statement, for instance...

ORDER ID -> ITEM FROM WEB PAGE

ITEM 1 ---> FROM TABLE 1
COUNT 1 ---> FROM TABLE 1
COUNT 2 ---> FROM TABLE 1

help...
Go to Top of Page

azwiefel
Starting Member

7 Posts

Posted - 2003-08-28 : 01:15:31
FOLLOW UP---
I need to add @transid and @siteID parameters to the insert string... WHERE/ HOW WOULD I DO IT?

CREATE PROCEDURE TEST
(
@transID bigint,
@siteID int,
@equipmentID int

)
AS
SET NOCOUNT OFF;
INSERT INTO TRANSACTIONS_EquipmentCounters
(transID, siteID, counterID, refCount, startCount, endCount)

SELECT
?--->** @TRANSID ** <---?,
?---** @SITEID** <---? ,
dbo.EQUIPMENT_Counters.CounterID
dbo.EQUIPMENT_Counters.CounterStartCount,
dbo.EQUIPMENT_Counters.CounterLastCount,
SUM(dbo.EQUIPMENT_Counters.CounterLastCount - dbo.EQUIPMENT_Counters.CounterStartCount
FROM dbo.EQUIPMENT_Counters INNER JOIN
dbo.LABELTypesToMachineCounters ON dbo.EQUIPMENT_Counters.CounterID = dbo.LABELTypesToMachineCounters.counterID INNER JOIN
dbo.EQUIPMENT_Profiles ON dbo.EQUIPMENT_Counters.EquipmentID =
dbo.EQUIPMENT_Profiles.equipmentID
GROUP BY dbo.EQUIPMENT_Counters.EquipmentID,
dbo.EQUIPMENT_Counters.CounterStartCount,
dbo.EQUIPMENT_Counters.CounterLastCount,
dbo.EQUIPMENT_Counters.CounterTempStart,
dbo.EQUIPMENT_Counters.CounterID,
dbo.EQUIPMENT_Profiles.siteID

HAVING (dbo.EQUIPMENT_Counters.EquipmentID = @equipmentID)

GO

THANKS IN ADVANCE....
Go to Top of Page

mohdowais
Sheikh of Yak Knowledge

1456 Posts

Posted - 2003-08-28 : 02:53:14
Almost there....

CREATE PROCEDURE TEST
(
@transID bigint,
@siteID int,
@equipmentID int

)
AS
SET NOCOUNT OFF

INSERT INTO TRANSACTIONS_EquipmentCounters
(transID, siteID, counterID, refCount, startCount, endCount)

SELECT
@TRANSID,
@SITEID,
dbo.EQUIPMENT_Counters.CounterID,
dbo.EQUIPMENT_Counters.CounterStartCount,
dbo.EQUIPMENT_Counters.CounterLastCount,
SUM(dbo.EQUIPMENT_Counters.CounterLastCount - dbo.EQUIPMENT_Counters.CounterStartCount)
FROM dbo.EQUIPMENT_Counters INNER JOIN
dbo.LABELTypesToMachineCounters ON dbo.EQUIPMENT_Counters.CounterID = dbo.LABELTypesToMachineCounters.counterID INNER JOIN
dbo.EQUIPMENT_Profiles ON dbo.EQUIPMENT_Counters.EquipmentID =
dbo.EQUIPMENT_Profiles.equipmentID
GROUP BY dbo.EQUIPMENT_Counters.EquipmentID,
dbo.EQUIPMENT_Counters.CounterStartCount,
dbo.EQUIPMENT_Counters.CounterLastCount,
dbo.EQUIPMENT_Counters.CounterTempStart,
dbo.EQUIPMENT_Counters.CounterID,
dbo.EQUIPMENT_Profiles.siteID
HAVING (dbo.EQUIPMENT_Counters.EquipmentID = @equipmentID)


Owais



Make it idiot proof and someone will make a better idiot
Go to Top of Page

azwiefel
Starting Member

7 Posts

Posted - 2003-08-28 : 15:15:32
Thanks.... that was it...!
I appreciate your help tremendously!
Go to Top of Page
   

- Advertisement -