Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3225626
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:21:40+00:00 2026-05-17T16:21:40+00:00

Hallo All, Please help in determining the best procedure for the following problem. In

  • 0

Hallo All,

Please help in determining the best procedure for the following problem.

In a user interface, there is a provision to upload excel file. This is done by admin, once/twice in a day on a regular basis.

The code that i have used to upload excel file into sql server.

select * 
into #temp FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', 
    'Excel 8.0;Database=D:\Files\29.09.10\working_290910.xls;HDR=YES;IMEX=1', 
    'SELECT * FROM [2XX$]')

Once the upload is successful, i am using the logic and deleting all the unnecessary records..finally i will get a set of records, which i move into the corresponding tables. Finally i DELETE the temp table that i used for uploading. Here #temp.

This procedure has many problems. As the structure of #temp is not always same as excel assumes the datatype of that particular field based on the analysis of the data it has in first n records. For a particular field sometimes it assumes, the datatype as nvarchar(255) and some times text. So few functions throw an error message on these particular fields on the execution of the stored procedure..

Last time i had a similar problem, LTRIM is not working on text field..As excel assumed the datatype for a field in table #temp as text..

So i modified the code in such a way by creating the table,

CREATE TABLE temp_invoice(
    [Concession Number] varchar(30),
    [Status] char(10),
    [Sort] char(10),
    [Task code text] varchar(60),
    [Task resp#] varchar(10),
    [Person who complete the task] varchar(50),
    [Completed] datetime
) 

so that i can fix the datatypes and then move the data from excel…

EDIT IN QUERY:-

insert into temp(Completed)  
    SELECT CASE Completed when '00.00.0000' THEN null else Completed END  
       FROM OPENROWSET  
('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=D:\Files\12.10.10\MC01_PCTA00012_20101012.xls;HDR=YES;IMEX=1', 'select * from [Tabelle1$]') AS A;

Now i am having error message based on data. If in the first few rows, the field completed has ‘00.00.000’. Then its working fine. If it does not have the value in first few rows, it throws an error message.

Now in my excel file the data for the field [Completed] is 00.00.0000, so the error message is “Arithmetic overflow error converting expression in the datetime data type.
The statement has been terminated
.”

If i remove the records with date as 00.00.0000 then its working good. But i can’t manuelly do it everytime. Now i need to find a work around this problem.

thanks a lot for your patience in reading such a long mail..I really have no clue, whether the procedure that i am using is correct or not. I am just changing the code to overcome the errors…

Please suggest me an appropriate procedure for this this kind of requirements.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:21:41+00:00Added an answer on May 17, 2026 at 4:21 pm

    Thanks for all your responses..I have found a dirty trick for the problem, i have defined completed column data type as varchar(20). Uploading as it is..

    CREATE TABLE temp_invoice(
        [Concession Number] varchar(30),
        [Status] char(10),
        [Sort] char(10),
        [Task code text] varchar(60),
        [Task resp#] varchar(10),
        [Person who complete the task] varchar(50),
        [Completed] varchar(20)
    ) 
    
    INSERT INTO temp_invoice ([Concession Number],[Status],[Sort],[Task code text],[Task resp#],[Person who complete the task],[Completed])
    EXEC('SELECT A.[Concession Number],A.[Status],A.[Sort],A.[Task code text],LTRIM(str(A.[Task resp#],10,0)) as [Task resp#],
    A.[Person who complete the task], A.[Completed] 
    FROM OPENROWSET  
    (''Microsoft.Jet.OLEDB.4.0'',''Excel 8.0;Database=' + 'D:\Files\12.10.10\XCTH00759_20101012.xls' + ';HDR=YES;IMEX=1'','+'''select * from [Tabelle1$]'') AS A') ;
    

    After the upload, i am setting the value to NULL, if it has completed date value as ‘00.00.0000’. Then finally changing the datatype.

    UPDATE temp_invoice SET Completed = NULL
    where Completed = '00.00.0000'
    
    ALTER TABLE temp_invoice ALTER COLUMN Completed datetime
    

    Because all the other ways are failing at a stage based on the data..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.