SQL Syntax to fix date data overflow error

rallcorn

Well-known Member
Joined
Nov 11, 2008
Messages
1,027
I posted this on SQL Syntax to fix date data overflow error
(I'm new to PowerPivot and actually forgot the MrExcel.com had a PowerPivot forum :oops:)

When pulling data from AS400 tables in which date fields are blank, in the Table Import Wizard>Specify a SQL Query, the SQL stmt will validate properly and will import correctly within the Table Import Wizard design screen (the blank date fields populate with "1/1/0001 12:00:00 AM"), however, when PowerPivot trys to convert, the date field is a problem. I receive msg, "Data overflow converting to the data type for table xxxx column 'UPDATE_DATE'. The current operation was cancelled because another operation in the transaction failed."

I've found a couple of fixes in various posts, the problem is I don't know how to incorporate these fixes into the correct syntax within my SQL query stmt.
One suggested solution:
Select case when [STORE.CLOSED_DATE} = '1901/1/1' then null else [STORE.CLOSED_DATE] end as STORE.CLOSED_DATE from DATAWHSE.DWMIRROR.STORE STORE

Another solution was to "wrap" STORE.CLOSED_DATE in "to_char(STORE.CLOSED_DATE,'mm/dd/yyyy')

I do not know how/where to incorporate either of these in my SQL stmt.

Here's the SQL stmt (the problem fields are "STORE.OPENED_DATE" and "STORE.CLOSED_DATE", STORE.CLOSED_DATE_8 is OK because it is a string rather than a date )

Code:
SELECT STORE.STORE_NUMBER, STORE.CITY, STORE.STATE, STORE.DIVISION, STORE.REGION, STORE.DISTRICT, [COLOR=#ff0000][B]STORE.OPENED_DATE[/B][/COLOR], [COLOR=#ff0000][B]STORE.CLOSED_DATE[/B][/COLOR], STORE.CLOSED_DATE_8
FROM DATAWHSE.DWMIRROR.STORE STORE
WHERE (STORE.STORE_NUMBER>99)
ORDER BY STORE.STORE_NUMBER

I'd really appreciate any help you guys can offer. Thank you.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Code:
SELECT STORE.STORE_NUMBER, STORE.CITY, STORE.STATE, STORE.DIVISION, STORE.REGION, STORE.DISTRICT, STORE.OPENED_DATE, case when [STORE.OPENED_DATE} = '1901/1/1' then null else [STORE.OPENED_DATE] end as OPENED_DATE, STORE.CLOSED_DATE_8
FROM DATAWHSE.DWMIRROR.STORE STORE
WHERE (STORE.STORE_NUMBER>99)
ORDER BY STORE.STORE_NUMBER
 
Upvote 0
Thank you, thank you , thank you!!!!! You don't know how much benefit this is!!! I had to tweak just a bit, but works wonderfully.
 
Upvote 0

Forum statistics

Threads
1,224,005
Messages
6,175,910
Members
452,682
Latest member
ghorne

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top