sql server dts:
Can anyone give me some direction in how to make a package to do what this script is doing? I have been checking the dts related web sites and groups and haven't found what I need to understand how to do this. BEGIN TRANSACTION DECLARE @ULogin varchar(50), @UPassword varchar(50), @UFirstName varchar(25), @UMiddleName varchar(25), @ULastName varchar(25), @UCreateDate datetime, @UUpdateDate datetime, @UHeight decimal (5,2), @UMeas3 decimal (5,2), @UMeas4 decimal (5,2), @UMeas2 decimal (5,2), @UMeas1 decimal (5,2), @UFlex tinyint, @UWeight decimal (5,2), @UShoeSize decimal (5,2), @NewUserID int, @IsError bit SET @IsError = 0 DECLARE csrUsers CURSOR STATIC LOCAL FORWARD_ONLY FOR SELECT UID, UFirstName, UMiddleName, ULastName, UCreateDate, UUpdateDate, --// Data For Users And Customers Table ULogin, UPassword, --// Data For UserLogin Table UHeight, UMeas3, UMeas4, UMeas2, UMeas1, UFlex, UWeight, UShoeSize --// FROM [WS1].[dbo].[Users] WHERE (ULogin IS NOT NULL AND ULogin <> '') AND (UPassword IS NOT NULL AND UPassword <> '') AND (UFirstName IS NOT NULL AND UFirstName <> '') AND (ULastName IS NOT NULL AND ULastName <> '') open csrUsers FETCH NEXT FROM csrUsers INTO --// Data For Users And Customers Table @UFirstName, @UMiddleName, @ULastName, @UCreateDate, @UUpdateDate, --// Data For UserLogin Table @ULogin, @UPassword, --// Data For UserFit Table @UHeight, @UMeas3, @UMeas4, @UMeas2, @UMeas1, @UFlex, @UWeight, @UShoeSize WHILE @@FETCH_STATUS = 0 BEGIN --// Insert Into Users Table INSERT INTO [WS2].[dbo].[Users] ([FirstName], [MiddleName], [LastName], [CreateDate], [UpdateDate]) VALUES (@UFirstName, @UMiddleName, @ULastName, @UCreateDate, @UUpdateDate) SET @NewUserID = SCOPE_IDENTITY() --// Insert Into Customers Table INSERT INTO [WS2].[dbo].[Customers] ([CustomerID]) VALUES (@NewUserID) --// Insert Into UserLogin INSERT INTO [WS2].[dbo].[UserLogin] ([UserID], [Username], [Password]) VALUES (@NewUserID, @ULogin, @UPassword) --// Insert Into EmailAddresses INSERT INTO [WS2].[dbo].[EmailAddresses] ([IsPrimary], [UserID], [Email]) VALUES (1, @NewUserID, @ULogin) IF (@UHeight IS NULL) BEGIN SET @UHeight = 0 END IF (@UMeas3 IS NULL) BEGIN SET @UMeas3 = 0 END IF (@UMeas4 IS NULL) BEGIN SET @UMeas4 = 0 END IF (@UMeas2 IS NULL) BEGIN SET @UMeas2 = 0 END IF (@UMeas1 IS NULL) BEGIN SET @UMeas1 = 0 END IF (@UFlex IS NULL) BEGIN SET @UFlex = 0 END IF (@UWeight IS NULL) BEGIN SET @UWeight = 0 END IF (@UShoeSize IS NULL) BEGIN SET @UShoeSize = 0 END IF (@UHeight > 0 AND @UMeas3 > 0 AND @UMeas4 > 0 AND @UMeas2 > 0 AND @UMeas1 > 0 AND @UFlex > 0 AND @UWeight > 0 AND @UShoeSize > 0) BEGIN --// Insert Into UserFit INSERT INTO [WS2].[dbo].[UserFit] ([UserID], [Height], [SternumNotch], [Inseam], [ArmLength], [ShoulderWidth], [Flexibility], [Weight], [ShoeSize]) VALUES (@NewUserID, @UHeight, @UMeas3, @UMeas4, @UMeas2, @UMeas1, @UFlex, @UWeight, @UShoeSize) END FETCH NEXT FROM csrUsers INTO --// Data For Users And Customers Table @UFirstName, @UMiddleName, @ULastName, @UCreateDate, @UUpdateDate, --// Data For UserLogin Table @ULogin, @UPassword, --// Data For UserFit Table @UHeight, @UMeas3, @UMeas4, @UMeas2, @UMeas1, @UFlex, @UWeight, @UShoeSize END CLOSE csrUsers DEALLOCATE csrUsers IF( @@ERROR <> 0 ) SET @IsError = 1 IF( @IsError = 0 ) COMMIT TRANSACTION ELSE ROLLBACK TRANSACTION GO thanks,
Aaron, Start a new package and include the script into Execute SQL task. Ilya [quoted text, click to view] "Aaron Prohaska" <REMOVE_THISmohaaron@gmail.com> wrote in message news:u41snTOpEHA.3464@TK2MSFTNGP14.phx.gbl... > Can anyone give me some direction in how to make a package to do what > this script is doing? I have been checking the dts related web sites and > groups and haven't found what I need to understand how to do this. > > BEGIN TRANSACTION > > DECLARE > @ULogin varchar(50), > @UPassword varchar(50), > @UFirstName varchar(25), > @UMiddleName varchar(25), > @ULastName varchar(25), > @UCreateDate datetime, > @UUpdateDate datetime, > @UHeight decimal (5,2), > @UMeas3 decimal (5,2), > @UMeas4 decimal (5,2), > @UMeas2 decimal (5,2), > @UMeas1 decimal (5,2), > @UFlex tinyint, > @UWeight decimal (5,2), > @UShoeSize decimal (5,2), > @NewUserID int, > @IsError bit > > SET @IsError = 0 > > DECLARE csrUsers CURSOR STATIC LOCAL FORWARD_ONLY FOR > SELECT > UID, UFirstName, UMiddleName, ULastName, UCreateDate, UUpdateDate, > --// Data For Users And Customers Table > ULogin, UPassword, --// Data For UserLogin Table > UHeight, UMeas3, UMeas4, UMeas2, UMeas1, UFlex, UWeight, UShoeSize --// > FROM > [WS1].[dbo].[Users] > WHERE > (ULogin IS NOT NULL AND ULogin <> '') > AND > (UPassword IS NOT NULL AND UPassword <> '') > AND > (UFirstName IS NOT NULL AND UFirstName <> '') > AND > (ULastName IS NOT NULL AND ULastName <> '') > > open csrUsers > > FETCH NEXT > FROM > csrUsers > INTO > --// Data For Users And Customers Table > @UFirstName, @UMiddleName, @ULastName, @UCreateDate, @UUpdateDate, > --// Data For UserLogin Table > @ULogin, @UPassword, > --// Data For UserFit Table > @UHeight, @UMeas3, @UMeas4, @UMeas2, @UMeas1, @UFlex, @UWeight, @UShoeSize > > WHILE @@FETCH_STATUS = 0 > BEGIN > --// Insert Into Users Table > INSERT INTO [WS2].[dbo].[Users] > ([FirstName], [MiddleName], [LastName], [CreateDate], [UpdateDate]) > VALUES > (@UFirstName, @UMiddleName, @ULastName, @UCreateDate, @UUpdateDate) > > SET @NewUserID = SCOPE_IDENTITY() > > --// Insert Into Customers Table > INSERT INTO [WS2].[dbo].[Customers] > ([CustomerID]) > VALUES > (@NewUserID) > > --// Insert Into UserLogin > INSERT INTO [WS2].[dbo].[UserLogin] > ([UserID], [Username], [Password]) > VALUES > (@NewUserID, @ULogin, @UPassword) > > --// Insert Into EmailAddresses > INSERT INTO [WS2].[dbo].[EmailAddresses] > ([IsPrimary], [UserID], [Email]) > VALUES > (1, @NewUserID, @ULogin) > > IF (@UHeight IS NULL) BEGIN > SET @UHeight = 0 > END > IF (@UMeas3 IS NULL) BEGIN > SET @UMeas3 = 0 > END > IF (@UMeas4 IS NULL) BEGIN > SET @UMeas4 = 0 > END > IF (@UMeas2 IS NULL) BEGIN > SET @UMeas2 = 0 > END > IF (@UMeas1 IS NULL) BEGIN > SET @UMeas1 = 0 > END > IF (@UFlex IS NULL) BEGIN > SET @UFlex = 0 > END > IF (@UWeight IS NULL) BEGIN > SET @UWeight = 0 > END > IF (@UShoeSize IS NULL) BEGIN > SET @UShoeSize = 0 > END > > IF (@UHeight > 0 AND @UMeas3 > 0 AND @UMeas4 > 0 AND @UMeas2 > 0 AND > @UMeas1 > 0 AND @UFlex > 0 AND @UWeight > 0 AND @UShoeSize > 0) BEGIN > --// Insert Into UserFit > INSERT INTO [WS2].[dbo].[UserFit] > ([UserID], [Height], [SternumNotch], [Inseam], [ArmLength], > [ShoulderWidth], [Flexibility], [Weight], [ShoeSize]) > VALUES > (@NewUserID, @UHeight, @UMeas3, @UMeas4, @UMeas2, @UMeas1, @UFlex, > @UWeight, @UShoeSize) > END > > FETCH NEXT > FROM > csrUsers > INTO > --// Data For Users And Customers Table > @UFirstName, @UMiddleName, @ULastName, @UCreateDate, @UUpdateDate, > --// Data For UserLogin Table > @ULogin, @UPassword, > --// Data For UserFit Table > @UHeight, @UMeas3, @UMeas4, @UMeas2, @UMeas1, @UFlex, @UWeight, @UShoeSize > END > > CLOSE csrUsers > DEALLOCATE csrUsers > > IF( @@ERROR <> 0 ) SET @IsError = 1 > > IF( @IsError = 0 ) > COMMIT TRANSACTION > ELSE > ROLLBACK TRANSACTION > GO > > thanks, > > Aaron
[quoted text, click to view] Ilya Margolin wrote: > Aaron, > > Start a new package and include the script into Execute SQL task. > > Ilya > > "Aaron Prohaska" <REMOVE_THISmohaaron@gmail.com> wrote in message > news:u41snTOpEHA.3464@TK2MSFTNGP14.phx.gbl... > >>Can anyone give me some direction in how to make a package to do what >>this script is doing? I have been checking the dts related web sites and >>groups and haven't found what I need to understand how to do this. >> >>BEGIN TRANSACTION >> >>DECLARE >>@ULogin varchar(50), >>@UPassword varchar(50), >>@UFirstName varchar(25), >>@UMiddleName varchar(25), >>@ULastName varchar(25), >>@UCreateDate datetime, >>@UUpdateDate datetime, >>@UHeight decimal (5,2), >>@UMeas3 decimal (5,2), >>@UMeas4 decimal (5,2), >>@UMeas2 decimal (5,2), >>@UMeas1 decimal (5,2), >>@UFlex tinyint, >>@UWeight decimal (5,2), >>@UShoeSize decimal (5,2), >>@NewUserID int, >>@IsError bit >> >>SET @IsError = 0 >> >>DECLARE csrUsers CURSOR STATIC LOCAL FORWARD_ONLY FOR >>SELECT >>UID, UFirstName, UMiddleName, ULastName, UCreateDate, UUpdateDate, >>--// Data For Users And Customers Table >>ULogin, UPassword, --// Data For UserLogin Table >>UHeight, UMeas3, UMeas4, UMeas2, UMeas1, UFlex, UWeight, UShoeSize --// >>FROM >>[WS1].[dbo].[Users] >>WHERE >>(ULogin IS NOT NULL AND ULogin <> '') >>AND >>(UPassword IS NOT NULL AND UPassword <> '') >>AND >>(UFirstName IS NOT NULL AND UFirstName <> '') >>AND >>(ULastName IS NOT NULL AND ULastName <> '') >> >>open csrUsers >> >>FETCH NEXT >>FROM >>csrUsers >>INTO >>--// Data For Users And Customers Table >>@UFirstName, @UMiddleName, @ULastName, @UCreateDate, @UUpdateDate, >>--// Data For UserLogin Table >>@ULogin, @UPassword, >>--// Data For UserFit Table >>@UHeight, @UMeas3, @UMeas4, @UMeas2, @UMeas1, @UFlex, @UWeight, @UShoeSize >> >>WHILE @@FETCH_STATUS = 0 >>BEGIN >>--// Insert Into Users Table >>INSERT INTO [WS2].[dbo].[Users] >>([FirstName], [MiddleName], [LastName], [CreateDate], [UpdateDate]) >>VALUES >>(@UFirstName, @UMiddleName, @ULastName, @UCreateDate, @UUpdateDate) >> >>SET @NewUserID = SCOPE_IDENTITY() >> >>--// Insert Into Customers Table >>INSERT INTO [WS2].[dbo].[Customers] >>([CustomerID]) >>VALUES >>(@NewUserID) >> >>--// Insert Into UserLogin >>INSERT INTO [WS2].[dbo].[UserLogin] >>([UserID], [Username], [Password]) >>VALUES >>(@NewUserID, @ULogin, @UPassword) >> >>--// Insert Into EmailAddresses >>INSERT INTO [WS2].[dbo].[EmailAddresses] >>([IsPrimary], [UserID], [Email]) >>VALUES >>(1, @NewUserID, @ULogin) >> >>IF (@UHeight IS NULL) BEGIN >>SET @UHeight = 0 >>END >>IF (@UMeas3 IS NULL) BEGIN >>SET @UMeas3 = 0 >>END >>IF (@UMeas4 IS NULL) BEGIN >>SET @UMeas4 = 0 >>END >>IF (@UMeas2 IS NULL) BEGIN >>SET @UMeas2 = 0 >>END >>IF (@UMeas1 IS NULL) BEGIN >>SET @UMeas1 = 0 >>END >>IF (@UFlex IS NULL) BEGIN >>SET @UFlex = 0 >>END >>IF (@UWeight IS NULL) BEGIN >>SET @UWeight = 0 >>END >>IF (@UShoeSize IS NULL) BEGIN >>SET @UShoeSize = 0 >>END >> >>IF (@UHeight > 0 AND @UMeas3 > 0 AND @UMeas4 > 0 AND @UMeas2 > 0 AND >>@UMeas1 > 0 AND @UFlex > 0 AND @UWeight > 0 AND @UShoeSize > 0) BEGIN >>--// Insert Into UserFit >>INSERT INTO [WS2].[dbo].[UserFit] >>([UserID], [Height], [SternumNotch], [Inseam], [ArmLength], >>[ShoulderWidth], [Flexibility], [Weight], [ShoeSize]) >>VALUES >>(@NewUserID, @UHeight, @UMeas3, @UMeas4, @UMeas2, @UMeas1, @UFlex, >>@UWeight, @UShoeSize) >>END >> >>FETCH NEXT >>FROM >>csrUsers >>INTO >>--// Data For Users And Customers Table >>@UFirstName, @UMiddleName, @ULastName, @UCreateDate, @UUpdateDate, >>--// Data For UserLogin Table >>@ULogin, @UPassword, >>--// Data For UserFit Table >>@UHeight, @UMeas3, @UMeas4, @UMeas2, @UMeas1, @UFlex, @UWeight, @UShoeSize >>END >> >>CLOSE csrUsers >>DEALLOCATE csrUsers >> >>IF( @@ERROR <> 0 ) SET @IsError = 1 >> >>IF( @IsError = 0 ) >> COMMIT TRANSACTION >>ELSE >> ROLLBACK TRANSACTION >>GO >> >>thanks, >> >>Aaron > > >
I could drop the script into an execute sql task, though what I really was looking to do is create a package to replace the script. So I'm really wondering if its possible to create a package that will select and insert data in the same way that this script does it. Thanks for the response,
[quoted text, click to view] Allan Mitchell wrote: > You could also use Lookups (this is still Row * Row) > You could use intermediate work tables as well which if the rowset is large > may be quicker. >
How does using a Lookup help solve my problem? I'm not sure what you define as a large rowset, in this case the rowset is about 10,000 rows. Another problem that I'm currently having with this is that I just created the package using a Execute Script Task and when run its throwing an error that I can't track down. It seems that the script is also not being run as a transaction because its inserting the data and then the error happens and it doesn't role back all the inserted rows. Is there any way to find out what row is causing the insert failure?
You could also use Lookups (this is still Row * Row) You could use intermediate work tables as well which if the rowset is large may be quicker. -- Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP) www.SQLDTS.com - The site for all your DTS needs. www.Konesans.com [quoted text, click to view] "Ilya Margolin" <ilya_no_spam_@unapen.com> wrote in message news:%23r$pXbVpEHA.868@TK2MSFTNGP10.phx.gbl... > Aaron, > > Start a new package and include the script into Execute SQL task. > > Ilya > > "Aaron Prohaska" <REMOVE_THISmohaaron@gmail.com> wrote in message > news:u41snTOpEHA.3464@TK2MSFTNGP14.phx.gbl... >> Can anyone give me some direction in how to make a package to do what >> this script is doing? I have been checking the dts related web sites and >> groups and haven't found what I need to understand how to do this. >> >> BEGIN TRANSACTION >> >> DECLARE >> @ULogin varchar(50), >> @UPassword varchar(50), >> @UFirstName varchar(25), >> @UMiddleName varchar(25), >> @ULastName varchar(25), >> @UCreateDate datetime, >> @UUpdateDate datetime, >> @UHeight decimal (5,2), >> @UMeas3 decimal (5,2), >> @UMeas4 decimal (5,2), >> @UMeas2 decimal (5,2), >> @UMeas1 decimal (5,2), >> @UFlex tinyint, >> @UWeight decimal (5,2), >> @UShoeSize decimal (5,2), >> @NewUserID int, >> @IsError bit >> >> SET @IsError = 0 >> >> DECLARE csrUsers CURSOR STATIC LOCAL FORWARD_ONLY FOR >> SELECT >> UID, UFirstName, UMiddleName, ULastName, UCreateDate, UUpdateDate, >> --// Data For Users And Customers Table >> ULogin, UPassword, --// Data For UserLogin Table >> UHeight, UMeas3, UMeas4, UMeas2, UMeas1, UFlex, UWeight, UShoeSize --// >> FROM >> [WS1].[dbo].[Users] >> WHERE >> (ULogin IS NOT NULL AND ULogin <> '') >> AND >> (UPassword IS NOT NULL AND UPassword <> '') >> AND >> (UFirstName IS NOT NULL AND UFirstName <> '') >> AND >> (ULastName IS NOT NULL AND ULastName <> '') >> >> open csrUsers >> >> FETCH NEXT >> FROM >> csrUsers >> INTO >> --// Data For Users And Customers Table >> @UFirstName, @UMiddleName, @ULastName, @UCreateDate, @UUpdateDate, >> --// Data For UserLogin Table >> @ULogin, @UPassword, >> --// Data For UserFit Table >> @UHeight, @UMeas3, @UMeas4, @UMeas2, @UMeas1, @UFlex, @UWeight, >> @UShoeSize >> >> WHILE @@FETCH_STATUS = 0 >> BEGIN >> --// Insert Into Users Table >> INSERT INTO [WS2].[dbo].[Users] >> ([FirstName], [MiddleName], [LastName], [CreateDate], [UpdateDate]) >> VALUES >> (@UFirstName, @UMiddleName, @ULastName, @UCreateDate, @UUpdateDate) >> >> SET @NewUserID = SCOPE_IDENTITY() >> >> --// Insert Into Customers Table >> INSERT INTO [WS2].[dbo].[Customers] >> ([CustomerID]) >> VALUES >> (@NewUserID) >> >> --// Insert Into UserLogin >> INSERT INTO [WS2].[dbo].[UserLogin] >> ([UserID], [Username], [Password]) >> VALUES >> (@NewUserID, @ULogin, @UPassword) >> >> --// Insert Into EmailAddresses >> INSERT INTO [WS2].[dbo].[EmailAddresses] >> ([IsPrimary], [UserID], [Email]) >> VALUES >> (1, @NewUserID, @ULogin) >> >> IF (@UHeight IS NULL) BEGIN >> SET @UHeight = 0 >> END >> IF (@UMeas3 IS NULL) BEGIN >> SET @UMeas3 = 0 >> END >> IF (@UMeas4 IS NULL) BEGIN >> SET @UMeas4 = 0 >> END >> IF (@UMeas2 IS NULL) BEGIN >> SET @UMeas2 = 0 >> END >> IF (@UMeas1 IS NULL) BEGIN >> SET @UMeas1 = 0 >> END >> IF (@UFlex IS NULL) BEGIN >> SET @UFlex = 0 >> END >> IF (@UWeight IS NULL) BEGIN >> SET @UWeight = 0 >> END >> IF (@UShoeSize IS NULL) BEGIN >> SET @UShoeSize = 0 >> END >> >> IF (@UHeight > 0 AND @UMeas3 > 0 AND @UMeas4 > 0 AND @UMeas2 > 0 AND >> @UMeas1 > 0 AND @UFlex > 0 AND @UWeight > 0 AND @UShoeSize > 0) BEGIN >> --// Insert Into UserFit >> INSERT INTO [WS2].[dbo].[UserFit] >> ([UserID], [Height], [SternumNotch], [Inseam], [ArmLength], >> [ShoulderWidth], [Flexibility], [Weight], [ShoeSize]) >> VALUES >> (@NewUserID, @UHeight, @UMeas3, @UMeas4, @UMeas2, @UMeas1, @UFlex, >> @UWeight, @UShoeSize) >> END >> >> FETCH NEXT >> FROM >> csrUsers >> INTO >> --// Data For Users And Customers Table >> @UFirstName, @UMiddleName, @ULastName, @UCreateDate, @UUpdateDate, >> --// Data For UserLogin Table >> @ULogin, @UPassword, >> --// Data For UserFit Table >> @UHeight, @UMeas3, @UMeas4, @UMeas2, @UMeas1, @UFlex, @UWeight, >> @UShoeSize >> END >> >> CLOSE csrUsers >> DEALLOCATE csrUsers >> >> IF( @@ERROR <> 0 ) SET @IsError = 1 >> >> IF( @IsError = 0 ) >> COMMIT TRANSACTION >> ELSE >> ROLLBACK TRANSACTION >> GO >> >> thanks, >> >> Aaron > >
Don't see what you're looking for? Try a search.
|