Search code examples
javascripthtmlsqlvbscripthta

Want to create SQL query generator for Email query


i have list of Multiple emails in excel and i have to run query everytime so it will be helpful if query creation will be done easily Thanks in Advance

Suppose multiple email id pasted on 1st text box and result will be shown in second text box. The output should be like this for example

Select id,name,emailid from data_d where emailid IN('[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]')

For now it removes spaces between emails but i am stuck at how to add the query in result

<html>
<head>

</head>
<body>
<div>
Enter Code:
</br>
<textarea id="getcode" style="width:500px; height: 100px;"> </textarea>
</br>
<input type="button" value='Convert' onclick="convert()"/>
</br>
<textarea id="displaycode" style="width:500px; height: 100px;"> </textarea>
</div>

<script type="text/javascript">
function convert() {
    var src = document.getElementById("getcode").value,
    str = src.replace(/[\r\n]+/g," ");
        arr = str.split(' ');

    document.getElementById("displaycode").value = arr.join("','");
}
</script>
</body>
</html>

Solution

  • <html>
    <head>
    
    </head>
    <body>
    <div>
    Enter Code:
    </br>
    <textarea id="getcode" style="width:1000px; height: 300px;"> </textarea>
    </br>
    <input type="button" value='Convert' onclick="convert()"/>
    </br>
    <textarea id="displaycode" style="width:1000px; height: 300px;"> </textarea>
    </div>
    <script type="text/javascript">
    function convert() {
        var src = document.getElementById("getcode").value,
        str = src.replace(/[\r\n\s]+/g," ");
            arr = str.split(' ');
           selection  = arr.join("','");
           pagelink = 'Select id,name,emailid from data_d where emailid IN(',
           pagelin = ')',
         copytext =  pagelink + selection + pagelin, 
          document.getElementById("displaycode").value = copytext
    }
    </script>
    </body>
    </html>
    

    Still there is one issue first and last email Address has ', extra comma.