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 |
|
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,f3from table1where <some criteria>- Jeff |
 |
|
|
azwiefel
Starting Member
7 Posts |
Posted - 2003-08-27 : 23:10:14
|
| Thanks... I knew I was being a bozo... |
 |
|
|
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 1COUNT 2 ---> FROM TABLE 1help... |
 |
|
|
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.CounterStartCountFROM dbo.EQUIPMENT_Counters INNER JOINdbo.LABELTypesToMachineCounters ON dbo.EQUIPMENT_Counters.CounterID = dbo.LABELTypesToMachineCounters.counterID INNER JOINdbo.EQUIPMENT_Profiles ON dbo.EQUIPMENT_Counters.EquipmentID = dbo.EQUIPMENT_Profiles.equipmentIDGROUP BY dbo.EQUIPMENT_Counters.EquipmentID, dbo.EQUIPMENT_Counters.CounterStartCount, dbo.EQUIPMENT_Counters.CounterLastCount, dbo.EQUIPMENT_Counters.CounterTempStart, dbo.EQUIPMENT_Counters.CounterID, dbo.EQUIPMENT_Profiles.siteIDHAVING (dbo.EQUIPMENT_Counters.EquipmentID = @equipmentID)GOTHANKS IN ADVANCE.... |
 |
|
|
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)ASSET NOCOUNT OFFINSERT 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 JOINdbo.LABELTypesToMachineCounters ON dbo.EQUIPMENT_Counters.CounterID = dbo.LABELTypesToMachineCounters.counterID INNER JOINdbo.EQUIPMENT_Profiles ON dbo.EQUIPMENT_Counters.EquipmentID = dbo.EQUIPMENT_Profiles.equipmentIDGROUP BY dbo.EQUIPMENT_Counters.EquipmentID, dbo.EQUIPMENT_Counters.CounterStartCount, dbo.EQUIPMENT_Counters.CounterLastCount, dbo.EQUIPMENT_Counters.CounterTempStart, dbo.EQUIPMENT_Counters.CounterID, dbo.EQUIPMENT_Profiles.siteIDHAVING (dbo.EQUIPMENT_Counters.EquipmentID = @equipmentID)Owais Make it idiot proof and someone will make a better idiot |
 |
|
|
azwiefel
Starting Member
7 Posts |
Posted - 2003-08-28 : 15:15:32
|
| Thanks.... that was it...!I appreciate your help tremendously! |
 |
|
|
|
|
|
|
|