Skip to content

Instantly share code, notes, and snippets.

@JamoCA
Created July 26, 2013 15:30
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamoCA/6089803 to your computer and use it in GitHub Desktop.
Save JamoCA/6089803 to your computer and use it in GitHub Desktop.
AutoHotKey script to convert clipboard columnar data (from Excel or text file) to SQL-compatible comma-delimited list (adds single quotes if data consists of non-numeric values) (Windows+C)
#c:: ;Window+C Convert Columnar Data to SQL-Compatible List
StringReplace,clipboard,clipboard,`n,`,,All
StringReplace,clipboard,clipboard,`r,,All
StringGetPos, pos, clipboard, ID`, ; remove "ID" if first item in the list (Access).
if pos = 0
StringRight, clipboard, clipboard, StrLen(clipboard)-3
testString = %clipboard%
StringReplace,testString,testString,`,,,All
testString := testString * 1
if (testString is integer) {
} else {
StringReplace,clipboard,clipboard,`,,'`,',All
clipboard = '%clipboard%'
}
Send,^v
Return
@alucchini1
Copy link

Hey - Thank you so much for this! super helpful!

Quick question - how would it look like if we wanted to paste it all in side a single quote, separated by comma, regardless if that is a string, integer, etc?

Thank you!

@JamoCA
Copy link
Author

JamoCA commented Sep 19, 2023

Is this what you are looking for?

#c::  ;Window+C  Convert columnar data to comma-delimited list within single quotes.
StringReplace,clipboard,clipboard,`n,`,,All
StringReplace,clipboard,clipboard,`r,,All
StringGetPos, pos, clipboard, ID`,  ; remove "ID" if it is the first item in the list.
if pos = 0
	StringRight, clipboard, clipboard, StrLen(clipboard)-3
clipboard = '%clipboard%'
Send,^v
Return

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment