SQL Data + Price Update in Great Plains Dynamics

Hi! I have a problem. I have this excel spreadsheet with over 2K rows.
I need to update a price list in SQL / Great Plains Dynamics. The table is IV00108

Current the table has item number, item description, and four (4) price levels:
1-9, 10-49, 50-99, 100+

The excel spreadsheet i have - has the item number, item description, and four (4) NEW price levels:
1-10, 11-50, 51-100, 101+

Is there any easy way to do this? Should I do it thru SQL Management Studio 2012 and how? Should I do it thru integration manager and how?

I am a noob and trying to learn. If ANYONE can help I would be appreciative!!!
niccrossAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MlandaTCommented:
You can use the OPENROWSET to read your Excel as if it were just any other SQL View/Table.

To view the data from Excel
/*Typically uses your first row as column names. A good idea to do a SELECT * so yo u can see the column names*/
SELECT *
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
		'Excel 8.0;Database=C:\Source\Addresses.xls;IMEX=1',
		'SELECT * FROM [Sheet1$]')

Open in new window


And the update
WITH ExcelData(
        /*Typically uses your first row as column names. A good idea to do a SELECT * so yo u can see the column names*/
        SELECT ItemNumber, ItemDescription, PriceLevel1, PriceLevel2, PriveLevel3, PriceLevel4
        FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
                        'Excel 8.0;Database=C:\Source\Addresses.xls;IMEX=1',
                        'SELECT * FROM [Sheet1$]')
)
UPDATE IV00108 SET
	PriceLevel1 = ExcelData.PriceLevel1,
	PriceLevel2 = ExcelData.PriceLevel2,
	PriveLevel3 = ExcelData.PriveLevel3,
	PriceLevel4 = ExcelData.PriceLevel4
FROM IV00108 
	INNER JOIN ExcelData ON ExcelData.ItemNumber = IV00108.ItemNumber

Open in new window

0
niccrossAuthor Commented:
Sorry my mistake that I did not give the detail that in the actual SQL table the field is: PRCLVEL and that has the description of 10-49 ... ETC

The excel sheet has the columns 1-10, 11-49 , etc
0
MlandaTCommented:
WITH ExcelData(
        /*Typically uses your first row as column names. A good idea to do a SELECT * so yo u can see the column names*/
        SELECT ItemNumber, ItemDescription, [1-9] as PriceLevel1, [10-49] as PriceLevel2, [50-99] as PriveLevel3, [100+] as PriceLevel4
        FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
                        'Excel 8.0;Database=C:\Source\Addresses.xls;IMEX=1',
                        'SELECT * FROM [Sheet1$]')
)
UPDATE IV00108 SET 
	VALUE_COLUMN = CASE PRCLVEL
					WHEN '1-9' THEN ExcelData.PriceLevel1
					WHEN '10-49' THEN ExcelData.PriceLevel1
					WHEN '50-99' THEN ExcelData.PriceLevel1
					WHEN '100+' THEN ExcelData.PriceLevel1
					ELSE VALUE_COLUMN
				END
FROM IV00108 
	INNER JOIN ExcelData ON ExcelData.ItemNumber = IV00108.ItemNumber

Open in new window

1
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

niccrossAuthor Commented:
MlandaT ... if I may be so bold as to ask you to look at this excel spreadsheet. The first sheet is the actual export from SQL ... the second excel spreadsheet so that you have the picture of it all. I think i blew an error when I tried the code.
Workbook1.xlsx
0
MlandaTCommented:
Please check this fiddle (http://sqlfiddle.com/#!3/4d8ef/1) and let me know if the UPDATETO column is reflecting the correct thing.
0
niccrossAuthor Commented:
WOW didn't know SQLFiddle existed!
It does reflect on what it needs to be.

I get this when I run the EXCEL command from SQL:

WITH ExcelData(
        /*Typically uses your first row as column names. A good idea to do a SELECT * so yo u can see the column names*/
        SELECT *
        FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
                        'Excel 8.0;Database=C:\Source\Addresses.xls;IMEX=1',
                        'SELECT * FROM [Sheet1$]')
)

Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'SELECT'.
Msg 102, Level 15, State 1, Line 8
Incorrect syntax near ')'.
0
MlandaTCommented:
Ooops! Sorry.. please make that first line: WITH ExcelData as (. i left out the *as*
0
niccrossAuthor Commented:
WITH ExcelData as (
        /*Typically uses your first row as column names. A good idea to do a SELECT * so yo u can see the column names*/
        SELECT *
        FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
                        'Excel 8.0;Database=C:\nbsprice.xls;IMEX=1',
                        'SELECT * FROM [Sheet1$]')
)

Msg 102, Level 15, State 1, Line 8
Incorrect syntax near ')'.
0
niccrossAuthor Commented:
I still get this error:
Msg 102, Level 15, State 1, Line 8
Incorrect syntax near ')'.
0
MlandaTCommented:
Into which IV00108 column do you wan to put the value from the Excel file?

Here is a fiddle with the update: http://sqlfiddle.com/#!3/38e1b/2
It shows the BEFORE and AFTER. You can BUILD SCHEMA (on the LEFT to reset the tables and start again)
0
niccrossAuthor Commented:
The UOMPRICE column in SQL is the one that is getting replace with the new pricing that is dictated by the PRCLEVEL.
0
MlandaTCommented:
Incorrect syntax near ')'.
A WITH (or CTE) creates an in-memory (sort of) data table. You actually need a SELECT after the WITH, coz it's meaningless on its own. The syntax in SQL Server is:
WITH tablename AS (
     ---a query to return the data from somewhere
     SELECT ... FROM. ...
)
SELECT * FROM tablename
0
niccrossAuthor Commented:
i sent you a private message also.
0
MlandaTCommented:
Your final query will look like this:
WITH ExcelData as (
        /*Typically uses your first row as column names. A good idea to do a SELECT * so yo u can see the column names*/
        SELECT *
        FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
                        'Excel 8.0;Database=C:\Source\Addresses.xls;IMEX=1',
                        'SELECT * FROM [Sheet1$]')
)
UPDATE IV00108 SET UOMPRICE = CASE PRCLEVEL
					WHEN '1-10' THEN ExcelData.C1_10
					WHEN '11-50' THEN ExcelData.C11_50
					WHEN '51-100' THEN ExcelData.C51_100
					WHEN '101' THEN ExcelData.C101
					ELSE UOMPRICE
				END
FROM IV00108
	INNER JOIN ExcelData ON IV00108.ITEMNMBR = ExcelData.Item
WHERE PRCLEVEL IN ('1-10', '11-50', '51-100', '101');

Open in new window

I jsut don't know what column names will come from your Excel file. Might be a good idea to tweak the column names into more SQL friendly names as I did (C1_10, C11_50, etc)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
niccrossAuthor Commented:
a great person and VERY experienced programmer!!
0
MlandaTCommented:
Thanks Niccross :). Glad to have helped.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.