Formula Forensics No. 031 – Production Scheduling using Excel

Share

Facebook
Twitter
LinkedIn

Recently, Bluetaurean asked in the Chandoo.org Forums about ways to allocate work durations for various product lines across 24 hour days to create a daily schedule.

Both formula-based and VBA-based solutions were offered.

Today at formula Forensics we will take a look at the formula-based approach.

As always at Formula Forensics you can follow along, Download Here – Excel 2007-2013.

 

Set the Scene

Since one might encounter a similar need in a variety of contexts (manufacturing, engineering, project planning, etc.), we will look at a more general problem of allocating a set of tasks and corresponding durations to one or more days, as shown in the following diagram.

We will create two output views:

  • One that is a flat list that can then be manipulated further using Excel’s Pivot table feature, and
  • Another view that mimics a pivot-table (and is similar to a typical project Gantt view, but with actual values listed instead of a bar chart).

You can follow along using the attached Excel document. Download here Excel 2007+

 

Problem Specifics

  • We have a list of tasks and their durations.
  • We need to distribute the tasks to different days, without exceeding the maximum available duration in a given day.
  • When the hours in a day are “used up”, we need to allocate the remaining task duration to the next day, and so on.
  • On the other hand, if a given task does not use up all of the hours in a given day, we will need to assign more than one task for that day, provided the combined durations do not exceed the available hours for that day.
  • In other words, we will need to split a task across one or more days, or combine one or more tasks into a single day, as needed, to maximize the work performed in a given day.

 

Developing the Approach

Before we tackle this problem in Excel, let us review how we might do this manually. Like most things, we might use the following three step process:

  1. Take the first task and assign its duration to Day 1. If the task’s duration exceeds the maximum hours available in a day, allocate the portion of the duration that does not fit into Day 1 into Day 2.
  2. Take the second task, and see whether it can fit into an existing day, or whether it needs to be distributed to multiple days
  3. Etc. (OK… so that three-step process was a stretch!)

Statistics show that most people think in terms of IF-THEN-ELSE statements. So here it is…

For a given Day, and for a given Task,
If [Hours Not Allocated For that Task] > [Hours Available for that Day] Then
Set Duration for that Day as [Hours Available for that Day]
Else
Set Duration for that Day as [Hours Not Allocated for that Task]
End
Continue the above evaluation until all tasks have been allocated to days.
 

Of course, the above IF() logic can be condensed as follows:

MIN( [Hours Not Allocated For that Task][Hours Available for that Day] )

 

Putting it All Together: Output Option 1: Gantt-like View

Let us employ the above approach to create the Gantt-like view.

To make our approach more generic, we will use an Excel Name called “MaxHrsPerDay” to indicate the maximum available hours in a given day. (In the sample worksheet, it has been set to 24 hours.)

Our source data is setup as shown in the diagram below:

  • Tasks are in the range A2:A5
  • Durations are in the range B2:B5

We will create the output in a separate worksheet, in the range A1:E5 as shown below:

Put the following formula into cell A2 and copy down to A5:

=SourceData!$A2

(This formula is merely referencing the values from the SourceData sheet. The sample workbook also includes an approach to make this reference more location independent.)

Put the following formula in cell B2, and copy it down and right:

=MIN((SourceData!$B2-SUM($A2:A2)), (MaxHrsPerDay-SUM(B$1:B1)))

 

Setup the header row (B1:E1) as desired. (I have used text values for the header. You could also calculate the header text using formulas. Since that is straightforward, I will leave that as an exercise for the reader.)

Now let us look at what the formula in cell B2 is doing:

  • SUM($A2:A2) is calculating the sum of the allocated durations for TaskA. (Please note the use of absolute and relative references. The formula is anchored on column A, but the starting row, ending row and ending column are free to expand.) SUM($A2:A2) returns zero since SUM() ignores text values.

– If you look at cell C2, the reference changes to SUM($A2:B2).
– In cell B3, the reference changes to SUM($A3:A3). You get the idea

  • (SourceData!$B2-SUM($A2:A2)) calculates the difference between the duration for TaskA (40 in the example) and the hours allocated as of that point (0), to return 40-0=40.
  • SUM(B$1:B1) is calculating the sum of the allocated hours for Day1. (Again, we are using a combination of absolute and relative references to keep the calculation anchored on column B.) In this case, the value is zero, since this is the first allocation for Day1.
  • (MaxHrsPerDay-SUM(B$1:B1)) calculates the hours remaining (i.e. available) for Day1. Since this is for cell B2, the calculation returns 24 – 0 = 24.

That is it!

We put those absolute and relative references to good use!

This approach was easy because all we had to do was calculate the duration for a given task for a given day.

 

On the other hand, if we had to figure out what the Task was, or which Day it was, the calculation gets a little more involved. Since this is “formula forensics”, we would not have it any other way! 🙂

 

Putting it All Together: Output Option 2: A Sequential List of Tasks and Durations for Each Day (i.e. a Flat List)

As before, we will use the Excel Name “MaxHrsPerDay” to refer to the maximum hours in a Day.

As shown in the following diagram, we will turn the source data into a flat list of Days, Tasks and Durations:

Unlike with VBA, since a formula cannot choose which row and column to write its output, we have to set the formula in every cell where we suspect there might be a value.

In the above sample diagram, we copy the formulas from row 2 to row 9. However, row 9 shows “…” indicating that the list was completed by row 8.

Let us look at how to determine the value for Day, Task and Allocated Duration.

For ease of description, I have created the following Excel Names:

WorkList: =A2:A5 in the source data.

WorkDuration: =B2:B5 in the source data

While creating the Gantt-like view earlier, we were able to take advantage of the static “Day” and “Task” values to determine the Remaining Duration, Available Duration, etc. Since we now have to determine all three values (Day, Task, Allocated Duration), we will need some “helper” data.

We will add a column alongside the source data that shows the cumulative duration (for reasons that will become clear shortly), as shown in the following diagram:

Cumulative Duration is calculated as the sum of all durations up to a given row.

  • For example, in cell C2, the Cumulative Duration is 40.
  • In cell C3, the Cumulative Duration is 40+20=60
  • And so on.

For ease of referencing, we will use an Excel Name called CumulativeDuration =C2:C5.

 

Let us look at why we need the “CumulativeDuration” helper column:

The circular logic problem

In order to determine the durations already allocated for a given day, we will need to know which Day it is.

We also need to know which Task we are trying to calculate the duration for.

So… do we calculate the Day or the Task or the Duration first?!! As you can imagine, that will soon land us in some circular logic.

 

Some helpful observations about the output:

  • In column C of the output (on worksheet FlatList), the sum of allocated durations adds up to the total duration for all tasks. (No surprise here!)
  • If every task had duration equal to the MaxHrsPerDay, you would have the same duration value for all days. (Not surprising, but interesting!)
  • In other words, you could think of the Allocated Duration column as the total duration for all tasks, allocated MaxHrsPerDay at a time.
  • Now we need a way to iterate through the duration values one at a time and account for the durations already processed. In other words, each value needs to contain all of the previous values. Welcome to an array of the cumulative durations!
  • For example, in the cumulative array “{40;60;65;80}”, the value 60 already includes the previous value 40 in it. This allows us to subtract all durations allocated up to a given row, to get the duration value that is remaining to be allocated.
  • Since Excel is good with numbers, we will base the calculation for AllocatedDuration and Tasks on the Duration values.
  • By calculating the two values separately, we avoid the circular logic.

Let’s now look at the formulas for Day, WorkItem and AllocatedDuration.

It would be easier if we looked at the formulas in reverse order, starting with AllocatedDuration, then WorkItem, and finally Day.

Formula for “AllocatedDuration”

Enter the following formula into cell C2, ending with Ctrl+Shift+Enter, as shown in the following diagram:

=IF(SUM(C$1:C1)>=SUMPRODUCT(WorkDuration), “…”,MIN(INDEX(WorkDuration, MATCH(TRUE, CumulativeDuration-SUM(C$1:C1) > 0, 0)) – SUMIFS(C$1:C1, B$1:B1,B2), MaxHrsPerDay-SUMPRODUCT((A$1:A1=A2)* IF(ISNUMBER(C$1:C1), C$1:C1, 0)))) Ctrl+Shift+Enter

Let us look at the formula closely (using the formula in row 2):

  • SUMPRODUCT((A$1:A1=A2)* IF(ISNUMBER(C$1:C1), C$1:C1, 0)) -> This calculates the sum of all allocated durations up to the previous row, where the Day = current row’s day. Please note the use of absolute and relative references. They allow us to expand the range as we go down the rows, while remaining anchored to the first row.

– Since this is the first data row, C$1:C1 returns “Allocated Duration” and the ISNUMBER() function returns FALSE, and consequently, the IF() function returns 0.
– A$1:A1 returns “Day”, and the test A$1:A1=A2 returns FALSE. Please note that in this case, it does not matter whether A2 has a value in it, whether it has the value 1, etc.
– SUMPRODUCT() provides the result of FALSE * 0 = 0

  • MaxHrsPerDaySUMPRODUCT((A$1:A1=A2)* IF(ISNUMBER(C$1:C1), C$1:C1, 0)) -> This calculates the difference between maximum duration available for a day and the sum of durations allocated for the current day. In other words, it calculates the available duration for the current row’s day.

– In this example, the calculation results in MaxHrsPerDay (24 in our example) – 0 = 24

  • SUMIFS(C$1:C1, B$1:B1,B2) -> This calculates the sum of all allocated durations for the current row’s task. Since B$1:B1 is the text value “Work Item”, the SUMIFS() returns 0. Again, it does not matter if B2 is blank or has a value like “TaskA”, since Excel correctly evaluates the condition whether B$1:B1 equals B2.
  • SUM(C$1:C1) -> This calculates the sum of all allocated durations up to the previous row.
  • CumulativeDurationSUM(C$1:C1) -> CumulativeDuration evaluates to {40;60;65;80}. SUM(C$1:C1) evaluates to zero. As such, the expression evaluates to {40;60;65;80} – 0, or {40;60;65;80}.

– If we look at the calculation for this expression in cell C3 (the expression would be “CumulativeDuration—SUM(C$1:C2)”), we would get the result of {40;60;65;80} – (0+24) = {16;36;41;56}. (As you know, subtracting a scalar value from an array results in an array with each value reduced by the scalar value.)

– If we look at the calculation for this expression in cell C4 (the expression would be “CumulativeDuration—SUM(C$1:C3)”) , we would get the result of {40;60;65;80} – (0+24+16) = {0;20;25;40}

– As you can see, each successive calculation reduces the CumulativeDuration array by the amount of hours already allocated. By reducing the CumulativeDuration array in this fashion, we ensure that we do not “double count” a duration.

– If a value in the array evaluates to zero, it means the corresponding duration has been fully allocated. (In cell C3, the first value in the array is zero, indicating that the original 40 hours has been fully allocated.) We will put this knowledge to good use in the next expression.

  • MATCH(TRUE, CumulativeDuration—SUM(C$1:C1) > 0, 0) -> The expression CumulativeDuration—SUM(C$1:C1) > 0 evaluates to ={TRUE;TRUE;TRUE;TRUE} because all values are greater than zero. By performing a MATCH() for TRUE, we are able to find the first location in the array that has a non-zero value.

– If we look at the result of this expression in cell C3, we get {16;36;41;56} > 0 = {TRUE;TRUE;TRUE;TRUE}

– If we look at the result of this expression in cell C4, we get {0;20;25;40} > 0 = {FALSE;TRUE;TRUE;TRUE}

– As you recall, the zero values (or FALSE) correspond to the durations that have been fully allocated, whereas, the non-zero values (or TRUE) correspond to the durations that have NOT been fully allocated.

– It is helpful to note that MATCH() returns the LOCATION of what it finds. As such, the returned location is that of the first duration value that has not been fully allocated! Since the CumulativeDuration array is the same size as the WorkDuration array, we will be able to put this returned location value to good use in the next expression.

  • INDEX(WorkDuration, MATCH(TRUE, CumulativeDuration — SUM(C$1:C1) > 0, 0)) -> By using the location value (of the first duration value that has not been fully allocated), we find the corresponding original duration value from the WorkDuration array.

– As we saw earlier, the expression “CumulativeDiration – SUM(C$1:C1)” reduces the CumulativeDuration by the duration values allocated to that point. However, the resulting array could have partial duration values as well. By referencing the corresponding duration value from the WorkDuration array, we ensure that we retrieve the original (full) duration value that was to be allocated.

  • MIN(…) -> This expression calculates the value of MIN([Hours Not Allocated For that Task], [Hours Available for that Day])

– [Hours Not Allocated For that Task] is returned by INDEX(WorkDuration, MATCH(TRUE, CumulativeDuration—SUM(C$1:C1) > 0, 0)) – SUMIFS(C$1:C1, B$1:B1,B2)

– [Hours Available for that Day] is returned by second half of the MIN() expression: MaxHrsPerDay—SUMPRODUCT((A$1:A1=A2)* IF(ISNUMBER(C$1:C1), C$1:C1, 0)).

– So, we essentially got back to the logic we started from, which is the same logic we used for creating the Gantt-like view as well.

  • The remaining portion of the formula (the IF() check) determines if all of the hours have been allocated. If all hours have been allocated, it returns “…”.

SUMPRODUCT(WorkDuration) -> This expression calculates the total of all work duration values. In cell C2, it evaluates to SUMPRODUCT({40;20;5;15}) = 80

SUM(C$1:C1)>=SUMPRODUCT(WorkDuration) -> Determines if the sum of durations allocated up to that point is greater than the total for all durations. (Since this is part of an array formula, you could also use the SUM function in place of SUMPRODUCT. But I am partial to the SUMPRODUCT function!! So, unless you are in a competition where the winner is determined by the shortest formula, feel free to use either one!

 

Formula for “WorkItem”

Enter the following formula into cell B2, ending with Ctrl+Shift+Enter, as shown in the following diagram.

=IF(SUM(C$1:C1)>=SUMPRODUCT(WorkDuration), “…”,INDEX(WorkList, MATCH(TRUE, (CumulativeDuration-SUM(C$1:C1)) > 0, 0))) Ctrl+Shift+Enter

You are already familiar with most of the formula components since you saw them in the formula for AllocatedDuration. The only difference is that in this formula, we are returning a value from WorkList. (i.e. we locate the position of the first non-zero duration in CumulativeDuration array, and since that array is the same size as the WorkList array, we are able to find the first Task that has not been fully allocated.)

Formula for “Day”

Enter the following formula into cell A2, ending with Ctrl+Shift+Enter, as shown in the following diagram:

=IF(SUM(C$1:C1)>=SUMPRODUCT(WorkDuration), “…”, MAX( N(A1) + (SUMIFS(C$1:C1, A$1:A1, A1)>=MaxHrsPerDay), 1)) Ctrl+Shift+Enter

Let us look at the formula in detail (using the formula in row 2):

  • SUMIFS(C$1:C1, A$1:A1, A1) -> This expression calculates the sum of all durations (in column C) where the Days (in column A) equal the previous day.

– In cell A2, this expression evaluates to “SUMIFS(“Allocated Duration”, “Day”, “Day”)” = 0. (Excel smartly ignores any non-numeric values in the first argument.)

– In cell A3, this expression evaluates to “SUMIFS({“Allocated Duration”;24}, {“Day”;1}, 1)” = 24.

  • SUMIFS(C$1:C1, A$1:A1, A1)>=MaxHrsPerDay -> This expression checks if the sum of all durations where the Days equal the previous day is greater than or equal to MaxHrsPerDay.

– In cell A2, this expression evaluates to FALSE

– In cell A3, this expression evaluates to TRUE

  • N(A1) -> This expression returns the numeric value for its argument. Since N() returns zero for any non-numeric arguments, we use this function to return zero for the heading (“Day”) in A1. (Any numeric values are returned as is.)
  • MAX( N(A1) + (SUMIFS(C$1:C1, A$1:A1, A1)>=MaxHrsPerDay), 1) -> The first argument of the MAX function “N(A1) + (SUMIFS(C$1:C1, A$1:A1, A1)>=MaxHrsPerDay)”returns the next increment for day, if the previous day has been fully allocated. Otherwise, it returns the same value as the previous day.

– In cell A2, this expression evaluates to MAX( N(“Day”) + (SUMIFS(“Allocated Duration”, “Day”, “Day”)>=24), 1), which evaluates to MAX( N(“Day”) + (0>=24), 1), which evaluates to MAX( 0 + (FALSE), 1), which finally evaluates to 1.

– In cell A3, this expression evaluates to MAX( N(1) + (SUMIFS({“Allocated Duration”;24}, {“Day”;1}, 1)>=24), which evaluates to MAX( N(1) + (24>=24), 1), which evaluates to MAX( 1+ (TRUE), 1), which finally evaluates to 2 since 1 + TRUE = 2.

 

Download

You can download a copy of the above file and follow along, Download Here – Excel 2007-2013.

 

Final Thoughts

While we used the same basic logic for both output options in this article, there are probably many other ways to tackle the age-old problem of production scheduling.

I would love to hear about some of your ideas, as well as ways to extend the concepts described here.

In the meantime, I wish you continued EXCELlence!

Sajan.

 

Other Chandoo.org Posts related to Scheduling

Here at Chandoo.org you can find the following related posts:

http://www.chandoo.org/wp/2010/11/18/scheduling-variable-sources/

http://chandoo.org/wp/2009/06/16/gantt-charts-project-management/

http://chandoo.org/wp/project-management-templates/gantt-charts/

 

Thank You

This was Sajan’s second post at Chandoo.org and so a special thank you to Sajan for putting pen to paper to describe the technique here.

You may want to read Sajan’s first post here or thank him in the comments below:

Formula Forensics “The Series”

This is the 31st post in the Formula Forensics series.

You can learn more about how to pull Excel Formulas apart in the following posts: Formula Forensic Series

 

Formula Forensics Needs Your Help

I need more ideas for future Formula Forensics posts and so I need your help.

If you have a neat formula that you would like to share like above, try putting pen to paper and draft up a Post like Sajan has done above or;

If you have a formula that you would like explained, but don’t want to write a post, send it to Hui or Chandoo.

Facebook
Twitter
LinkedIn

Share this tip with your colleagues

Excel and Power BI tips - Chandoo.org Newsletter

Get FREE Excel + Power BI Tips

Simple, fun and useful emails, once per week.

Learn & be awesome.

Welcome to Chandoo.org

Thank you so much for visiting. My aim is to make you awesome in Excel & Power BI. I do this by sharing videos, tips, examples and downloads on this website. There are more than 1,000 pages with all things Excel, Power BI, Dashboards & VBA here. Go ahead and spend few minutes to be AWESOME.

Read my storyFREE Excel tips book

Overall I learned a lot and I thought you did a great job of explaining how to do things. This will definitely elevate my reporting in the future.
Rebekah S
Reporting Analyst
Excel formula list - 100+ examples and howto guide for you

From simple to complex, there is a formula for every occasion. Check out the list now.

Calendars, invoices, trackers and much more. All free, fun and fantastic.

Advanced Pivot Table tricks

Power Query, Data model, DAX, Filters, Slicers, Conditional formats and beautiful charts. It's all here.

Still on fence about Power BI? In this getting started guide, learn what is Power BI, how to get it and how to create your first report from scratch.

41 Responses to “SQL Queries from Excel”

  1. Leonid says:

    I use this method very often.
    I always use =SUBSTITUTE (ColumnWithText,"'","''")
    to be sure that potential apostrophe in text columns are doubled as required in SQL.

  2. Chandoo says:

    @Leonid.. that is a good technique to use substitute to clean up text apostrophes. thanks

  3. Paul G. says:

    Goal:
    Generate update statement in excel where the columns that can be updated are dynamic
    You want the columns which are not updated to keep the same value
    (or not be overwritten with NULL values with the new generated statement)
    the statement can be applied to multiple rows in excel for the same column headers
    (This is why the '$' exist for the column headers that are being set)

    A1 = First_Name
    B1 = Last_Name
    C1 = Middle_Name

    ="
    UPDATE PERSONS "&CHAR(10)&
    " SET 1 = 1 "&CHAR(10)&
    IF(LEN(TRIM($A2))=0,"",", "&$A$1&" = '"&$A2&"'"&CHAR(10))&
    IF(LEN(TRIM($B2))=0,"",", "&$B$1&" = '"&$B2&"'"&CHAR(10))&
    IF(LEN(TRIM($C2))=0,"",", "&$C$1&" = '"&$C2&"'"&CHAR(10))&
    " WHERE name = 'staticordynamicvalue' AND gender = 'staticordynamicvalue'
    "
    Output (if all columns are set):
    UPDATE PERSONS SET 1 = 1,
    First_Name = 'Joe',
    Last_Name = 'ORien',
    Middle_Name = 'Richard'
    WHERE age = 28 AND gender = 'm'

    Output (if only First _Name (A1) is set):
    UPDATE PERSONS SET 1 = 1,
    First_Name = 'Joe'
    WHERE age = 28 AND gender = 'm'

  4. Paul G. says:

    Possibly my post above is confusing without the actual table to look at. I will do the same example with the table used here. Instead of an insert statement I will generate an update statement for the columns, Cust_Name, Phone & E-mail
    where we can generate an update statement for any column individually or together. 🙂 I hope this can help.
    =”
    UPDATE table “&CHAR(10)&
    ” SET 1 = 1 “&CHAR(10)&
    IF(LEN(TRIM($A2))=0,”",”,Cust_Name = ‘”&$B3&”‘”&CHAR(10))&
    IF(LEN(TRIM($B2))=0,”",”, Phone = ‘”&$C3&”‘”&CHAR(10))&
    IF(LEN(TRIM($C2))=0,”",”, E-mail = ‘”&$D3&”‘”&CHAR(10))&
    ” WHERE Cust_Name = ’Bill Gates'

  5. Visa Inde says:

    Thanks, it has been very useful !
    It saved me at least 30 minutes, and time is the most expensive thing in our world...

  6. Kad says:

    Hey Paul,
    What if any of A2, B2, or C2 is a date field?
    The formula above is taking date as string. Any solution?

    • Smitha says:

      Even I faced the same problem. If any of the above columns are date, it is taken  as string. Any work around for this?

  7. Sam Howley says:

    I've found the string concatenation method works well.

    At the risk of sounding spammy I would mention that
    if it's something your are doing regularly it might be worth investigating a tools
    that make it easier, such as QueryCell, an excel add-in I've developed.

    It gives you a right click menu option that will produce and then customize insert statements for the selected region of Excel data.

    Cheers
    Sam

    • Pravin says:

      Hi,
      For inserting the excel data to your SQL table, you can create insert statements in excel file according to your columns.
      then just execute the statements all at once, it will insert the required data to sql server table.
      thanks,

  8. Chetan Patil says:

    I tried to generate t-sql insert queries from the above example
    ="insert into values('" &A2 &"','" & B2& "');"
    but it generates on one record instead of all records from excel sheet.
    I'm using Excel 2003 and the excel sheet contains 922 records.

  9. Mike says:

    Most data bases can generate DDL for any object but not a lot of them allow generation of INSERT statements for the table data.
    The workaround is to make use of ETL Tools for transferring data across servers. However, there exists a need to generate INSERT statements from the tables for porting data.
    Simplest example is when small or large amount of data needs to be taken out on a removable storage media and copied to a remote location, INSERT..VALUES statements come handy.

    There is a number of scripts available to perform this data transformation task. The problem with those scripts that all of them database specific and they do not work with textiles

    Advanced ETL processor can generate Insert scripts from any data source including text files
    http://www.dbsoftlab.com/generating-insert-statements.html

  10. B.N.Prabhu says:

    Super Aiticle. Thanks for this post.

  11. I used to deal with the same problem, until found this awsome and free tool.
    http://www.xtrategics.com/shapp/String%20Handler.application

    regards,

  12. Archana says:

    Hi ,
    i need a sql query to update a DB in excel 2010..
    i have the query(SQL) for insert in excel as ,
    ="insert into customers values('" &B3 &"','" & C3 & "','"&D3&"');"

    similarly i need q sql query for update in excel

  13. shana says:

    i want clear formulas only for insert,delete,update,select

  14. Ankit Mahendru says:

    Hi !
    I would like to thank you so much ! This trick saves me a  lot of time. Thank you so much. Really appreciate it !
     
    -Ankit

  15. Richard says:

    You may like to take advantage of this unique tool 'Excel to Database'. 
    (free for 60 days)http://leansoftware.net The Excel-to-Database utility enables you to validate and transfer data from Microsoft Excel or text file to a database table or stored procedure process. Any text data can be pasted into the application, this may be from another Excel sheet or from text files such as CSV format. SQL Server, Access, MySQL, FoxPro .. Application features Some unique features of Excel to Database include: ?Easy to use color coded/traffic light data validation ?Data is validated as soon it is typed or pasted into Excel ?Upload Excel data to a table or stored procedure process ?Allow default values ?Mandatory/must have fields can be specified ?Allow user friendly column names ?Allow excel formula / calculated fields ?Multiple database type support: Microsoft SQL Server, Access, MySQL and others (to be tested) ?Supports Custom SQL scripts, with SQL/Excel merge fields ?Database validation checks ensure you comply with any rules defined within the database ?Multiple Task configuration ?For co-operative use, Tasks can be shared across a network ?Task configuration is password protected http://leansoftware.net 

  16. Manoraj says:

    Its works fine for single record.
    I want to update 1000 records in DB. Can you help me.

  17. Richard says:

    Excel database tasks 2.3 (EDT)
    you can now load directly from any source into Excel, validate and upload to most SQL database platforms including SQL Server with automatic transaction wrapping.
    You can also use EDT as a multi-user application by easily designing your own Edit data tasks and deploying EDT on your users workstations.
    Automatically creates UPDATE/INSERT statements based on the primary key.  Default SQL can be modified as you require.
    Makes the best use if Excel power - formatting, formula, validation, conditional formatting..  without creating any problematic spreadsheets!
    Release details on the blog:
    http://leansoftware.net/forum/en-us/blog.aspx
    Thanks for the interest
    Richard
     
     
     

  18. Usman says:

    Thanks for the valueable information, it really help me alot.
     
    Thanks again.

  19. Laercio says:

    As I do with a field of type date?
    = "UPDATE SET business datetime =" & "'" & A2 & "' WHERE ID =" & B2 & ""
    the date is not 03/10/2012 is 41246. Even putting quotes ...

  20. Elaein says:

    Please show how to do it properly with dates as well as when those dates are empty. Thanks!

  21. mahesh.S says:

    In a separate column make the date to Text using below formula
    =TEXT(C2,"mm/dd/yyyy") Then Refer this text column in your update statement

  22. cjb says:

    Great post saved me a a load of time on a task i had to complete

  23. sql010 says:

    thanks for sharing article... helpful!

  24. Pooja says:

    Thanks 🙂

  25. Hello,

    Nice article.

    I have also created one tool for create table script using excel http://devssolution.com/create-table-in-sql-using-excel/

    Please check it.

    Thanks & Regards,
    Sandeep Bhadauriya

  26. […] Excel formula used – http://chandoo.org/wp/2008/09/22/sql-insert-update-statements-from-csv-files/ […]

  27. HSoomro says:

    If any one can help me out with following.
    I want to know a SQL query of below excel formula:
    =LOOKUP(0,-SEARCH(LEFT(F2,LEN($B$2:$B$100))+0,$B$2:$B$100),$A$2:$A$100)

    Excel data is as below;
    Name Codes
    names1 992
    names2 57
    names3 856
    names4 297
    names5 63

    if there is a number (29756789) then it should search in sql by taking the prefix of number (297) from (29756789) and return the name field (name4).
    Codes can be of two digit or three.

    Thanks

  28. David says:

    Here is a link to an Online automator to convert CSV files to SQL Insert Into statements:

    CSV-to-SQL: http://csv-to-sql.herokuapp.com

  29. Victor R Udeshi says:

    ="INSERT INTO table VALUES (" &A3 &",'" & B3 & "','"&C3&"','" & D3 & "','" & E3 & "'," & F3 & "," & G3 & "," & H3 & ",'" & I3 & "'," & J3 & ");"

    B3 has date data that looks like 9/22/17 but with the formula above b3 is coming out as 43000?

    how do i fix that?

  30. Mr.Shan says:

    I just want to insert the Excel records in Sql table without Visiting SQL.
    basically i m just want to run a command in Excel Only.
    Help Me..plz..?

  31. Danyal Hussain says:

    Hi I have a question maybe you guys have an answer for me

    ="insert into customers values('" &B3 &"','" & C3 & "','"&D3&"');" where B3, C3, D3 refer to above table data.

    the above technique works but is there a way to write it so it takes a range instead of individual columns. because I have an extremely wide table

    ="insert into customers values(B3:D3);" where B3, C3, D3 refer to above table data.

  32. Qadir Bux says:

    Awsome

  33. Bhagwat says:

    Its Great Effort to help everyone who working with excel.

  34. Ed says:

    Thanks for the mini-tutorial on SQL from Excel. Didi it several years ago, but couldn't remember the syntax! All the dialogue was really helpful as well!

  35. Administrasi Bisnis says:

    The formula above is taking date as string. Any solution?

Leave a Reply