Uptime Legal Systems
asked on
SQL Import Question
I'm in the process of writing SQL to move our existing Access database [Upworks] to a new SQL database for ConnectWise.
Due to the structure of the tables not being in standard row/column format, I'm having to make passes at importing the data into the structure it needs to be in- but there are some discrepancies in the values that I would like to be able to adjust on the fly. For example:
This part:
Pulls the source (Google, Facebook, etc.) into the new table, but the source value is actually a number (1 - 9) in the old table. What I would like to be able to do is alter this so I can define a value based on whether it is 1-9 in the old table as it gets imported to the new one.
Any help is appreciated.
Due to the structure of the tables not being in standard row/column format, I'm having to make passes at importing the data into the structure it needs to be in- but there are some discrepancies in the values that I would like to be able to adjust on the fly. For example:
/* Declare vNumber as the operator for the per row run */
/* Draw this value from whatever we determine to be the primary key of the corresponding Upworks Column */
DECLARE @vNumber INT
SET @vNumber = (SELECT MIN([ContactID]) FROM [Upworks].[dbo].[Contacts])
/* Find the Maximum value */
DECLARE @MaxNumber INT
SET @MaxNumber = (SELECT MAX([ContactID]) FROM [Upworks].[dbo].[Contacts])
WHILE
@vNumber <= @MaxNumber
BEGIN
INSERT INTO Company_User_Defined_Field_Value (Company_User_Defined_Field_Value_RecID, Company_RecID, User_Defined_Field_RecID, User_Defined_Field_Value, Last_Update_UTC, Updated_By)
VALUES (
(SELECT ISNULL(MAX(Company_User_Defined_Field_Value_RecID)+1,1) FROM Company_User_Defined_Field_Value),
--Company_RecID,
(SELECT Company_RecID
FROM [cwwebapp_uptimelegal_new].[dbo].[Company]
WHERE Upworks_ContactID = @vNumber
),
2,
(SELECT Source
FROM [Upworks].[dbo].[Company]
WHERE ContactID = @vNumber
),
GETDATE(),
'Upworks'
)
SET @vNumber = @vNumber + 1
END
This part:
(SELECT Source
FROM [Upworks].[dbo].[Company]
WHERE ContactID = @vNumber
)
Pulls the source (Google, Facebook, etc.) into the new table, but the source value is actually a number (1 - 9) in the old table. What I would like to be able to do is alter this so I can define a value based on whether it is 1-9 in the old table as it gets imported to the new one.
Any help is appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Of course, I would love to keep it the same way it is (the source has tables) but the ConnectWise (application) database is already structured in a specific way and I have to accommodate it (frustrating).
(the tables are laid out like this)
http://filedb.experts-exchange.com/incoming/2015/10_w44/979401/sqltables.PNG
Thanks for the response!