all groups > sql server dts > september 2004 >
You're in the

sql server dts

group:

Create package in place of script


Create package in place of script Aaron Prohaska
9/27/2004 3:55:57 PM
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,

Re: Create package in place of script Ilya Margolin
9/28/2004 8:31:55 AM
Aaron,

Start a new package and include the script into Execute SQL task.

Ilya

[quoted text, click to view]

Re: Create package in place of script Aaron Prohaska
9/28/2004 11:47:58 AM
[quoted text, click to view]

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,

Re: Create package in place of script Aaron Prohaska
9/28/2004 1:01:24 PM
[quoted text, click to view]

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?

Re: Create package in place of script Allan Mitchell
9/28/2004 7:56:49 PM
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]

AddThis Social Bookmark Button