Skip to content

Instantly share code, notes, and snippets.

@JamoCA
Last active August 22, 2019 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamoCA/7737c8a18e1cfd7a6aecd79a19a96e03 to your computer and use it in GitHub Desktop.
Save JamoCA/7737c8a18e1cfd7a6aecd79a19a96e03 to your computer and use it in GitHub Desktop.
AutoHotKey script to convert a column of clipboard data (copied from Excel, Word, Outlook, text file, etc) to a SQL list for use in a IN() query.
; 20190822 https://gamesover2600.tumblr.com/post/187192578144/sql-macros-using-autohotkey-windows
^+l:: ;CTRL+Shift+L Takes clipboard and converts tab-delimited data to SQL-compatible comma-delimited row (adds single quotes if data consists of non-numeric values)
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
testString = %clipboard%
StringReplace,testString,testString,`,,,All
testString := testString * 1
if (testString is integer) {
} else {
StringReplace,clipboard,clipboard,`,,'`,',All
clipboard = '%clipboard%'
}
Send,^v
Return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment