Friday, September 28, 2007

Using Microsoft Excel for Desired Inputs.

Every now and then you get requirement to produce ad-hoc report or data extract for given sets of excel data. User might provide you names, IDs for which he is expecting the results, but the problem is putting all that input data into your SQL queries in a way that it will fulfill the Syntax.

For ex.
SELECT company_id, address, city, state, country
FROM company
WHERE company_name in (('IBM','Oracle','Apple','Google','MicroSoft')

--List of names given by user (without quotes and comma separated):-
IBM
Oracle
Apple
Google
MicroSoft

It is doable when the list is small containing 10/20 items, But it becomes tedious & impractical to do it manually when list has 1000’s of items.
So while extracting such data yesterday, I found an easy and effortless way of achieve this thing using Microsoft Excel.

Here are Pictorial step-by-step instructions:



First Select the required columns (Cell)
Then using right click select the ‘Format Cell’ Option
Then use ‘Custom’ and Type as ‘@’, and click OK.