Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Downgrade INSERT with OUTPUT to Sql Server 2000


Downgrade INSERT with OUTPUT to Sql Server 2000

Author
Message
TBIG
TBIG
Grasshopper
Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)

Group: General Forum Members
Points: 21 Visits: 96
How do I convert the following Sql script so that it will run on Sql Server 2000 (which does not support the OUTPUT feature?

--Create new locations and capture Location Name and new LocationIDs, AreaIDs in temp table _NewLocationis
INSERT INTO Locations ( [LocationName], [LocationOrder], [LocationNotes], [AreaID], [NumberInArea] )
--Add new inserted Locations into temp table _NewLocations
OUTPUT INSERTED.LocationID, INSERTED.LocationName, INSERTED.AreaID INTO _NewLocations (LocationID, LocationName,AreaID)
SELECT LocationName, LocationOrder, LocationNotes, @NewAreaID, NumberInArea
FROM Locations
WHERE AreaID=@AreaID
ORDER BY LocationID


Thanks!
Luis Cazares
Luis Cazares
SSCrazy Eights
SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)

Group: General Forum Members
Points: 8506 Visits: 18113
You could create a trigger for insert


CREATE TRIGGER TI_Locations ON Locations
AFTER INSERT
AS

INSERT INTO _NewLocations (LocationID, LocationName,AreaID)
SELECT LocationID, LocationName, AreaID
FROM Inserted




Luis C.
General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?


How to post data/code on a forum to get the best help: Option 1 / Option 2
Andrew G
Andrew G
SSCrazy
SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)

Group: General Forum Members
Points: 2010 Visits: 2228
Trigger is probably better, or put into a temp table and roll it all into a single transaction in case of failure.


BEGIN TRAN

--Create new locations and capture Location Name and new LocationIDs, AreaIDs in temp table _NewLocationis
SELECT LocationName, LocationOrder, LocationNotes, @NewAreaID, NumberInArea
INTO #LOCATIONS
FROM Locations
WHERE AreaID=@AreaID
--ORDER BY LocationID

INSERT INTO Locations ( [LocationName], [LocationOrder], [LocationNotes], [AreaID], [NumberInArea] )
--Add new inserted Locations into temp table _NewLocations
--OUTPUT INSERTED.LocationID, INSERTED.LocationName, INSERTED.AreaID INTO _NewLocations (LocationID, LocationName,AreaID)
SELECT LocationName, LocationOrder, LocationNotes, @NewAreaID, NumberInArea
FROM #LOCATIONS

IF @@ERROR<> 0
ROLLBACK

INSERT INTO _NewLocations (LocationID, LocationName,AreaID)
SELECT LocationID, LocationName, AreaID
FROM #LOCATIONS

IF @@ERROR<> 0
ROLLBACK
ELSE
COMMIT



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search