I did it a few groups earlier than realizing it is too painful and the scenario is just too frequent. I first tried to make use of a textual content editor like WordPad and Notepad to transform an inventory of values into one thing I can use within the IN clause of SQL.
I ultimately discover a easier answer to this drawback utilizing Microsoft Excel, a device that many people know however do not use successfully. Through the use of Microsoft excel you’ll be able to simply write a formulation to concatenate values from one column with single quotes and commas. Later you should utilize Excel’s fill method to repeat it general cell values and you might be accomplished.
Steps to surround an inventory of String into single quotes utilizing Microsoft Excel – Instance
Step 1:
Copy the record of values into the primary column (A) in your Excel Work Sheet
Step 2:
Copy the next formulation into the second column (B) on the first cell
=CHAR(39) & A1 & CHAR(39) & CHAR(44)
Right here 39 is the ASCII worth of single quote (‘) and 44 is the ASCII worth of the comma.
Step 3:
Drag this formulation to the remaining cell as proven under:
Step 4:
Now, column B has values which can be enclosed in single quotes and separated by a comma, you’ll be able to straight use them within the SQL question as proven under:
SELECT ClosingPrice from StockDetails the place Firm Title IN ( 'Ambalal Sarabhai Enterprises Ltd', 'Assambrook Ltd', 'PH Capital Ltd', 'Mavi Industries Ltd', 'Oswal Spinning & Weaving Mills Ltd', 'TPI India Ltd', 'Zuari Industries Ltd', 'Oscar Investments Ltd', 'Maestros Mediline Programs Ltd', 'Mediaone International Leisure Ltd', 'GEE Ltd', 'Kaycee Industries Ltd', 'Rathi Metal & Energy Ltd', 'Clutch Auto Ltd' )
Simply keep in mind to take away the comma from the final worth earlier than you copy them into SQL editor.
This properly solves the issue of changing an inventory of values into single quote enclosed and comma-separated values which can be utilized with SQL queries.
I’m not a Microsoft Excel knowledgeable however I’ve seen individuals utilizing Excel to resolve various kinds of issues like a while you get two lists of values and it’s a must to discover out which values are widespread and which values of 1 record would not exist on different, for this you should utilize the VLOOKUP perform of Microsoft Excel.
Good data of Microsoft Excel will significantly assist you in your day-to-day job whether or not you’re a developer, help skilled, challenge supervisor, or any technical person. I’m engaged on compiling some helpful Excel ideas for Java builders like this one. In case you have any, then please share with us. You too can see these greatest Microsoft Excel programs to be taught extra about easy methods to use Excel higher and extra productiveness.