{"id":13532,"date":"2021-12-13T11:15:05","date_gmt":"2021-12-13T11:15:05","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/?post_type=question&#038;p=13532"},"modified":"2021-12-13T11:15:52","modified_gmt":"2021-12-13T11:15:52","slug":"solved-executing-sql-queries-in-vbs-script","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/programming\/executing-sql-queries-in-vbs-script\/29158.html","title":{"rendered":"Solved Executing SQL Queries In VBS Script"},"content":{"rendered":"<p>Firstly :<br \/>\nI want to execute the SP and get the resultset in the attachement for mail.<br \/>\nSP name : Exec rpt_XC_BUF_SUM<br \/>\nDB : fi4_xc_prod<br \/>\nServer : FACETSRPT\\FACETS<\/p>\n<p>I want to capture the resultset of above SP into the txt file to be attached in mail.<\/p>\n<p>Secondly : I want to run the below query and capture the result set (that is count) into the Body of the mail.<br \/>\nDB : fi4_xc_prod<br \/>\nServer : FACETSRPT\\FACETS<br \/>\nQuery : select count(*) from fi4_xc_prod.dbo.XC_BUF where TBL_ORDER_ID=&#8217;C&#8217;<\/p>\n<p>The body of the mail shoulde be like :<br \/>\nListing of today&#8217;s claim batch ID&#8217;s and count is attached. Total Count: (From above query).<\/p>\n<p>The below is the mail script i have :<\/p>\n<p>SMTPServer = &#8220;mail.xxx.com&#8221;<br \/>\nRecipient = &#8220;suhail_abbas@xxx.com&#8221;<br \/>\nCc = &#8220;suhail_abbas@xxx.com&#8221;<br \/>\nFrom = &#8220;suhail_abbas@xxx.com&#8221;<br \/>\nSubject = &#8220;Test email&#8221;<br \/>\nMessage = &#8220;Listing of today&#8217;s claim batch ID&#8217;s and count is attached. Total Count: (From above query)&#8221;<br \/>\n&#8216;attachment = Here the attachment from the above SP result set. It should be text file<\/p>\n<p>GenericSendmail SMTPserver, From, Recipient, Subject, Message<\/p>\n<p>Sub GenericSendmail (SMTPserver, From, Recipient, Subject, Message)<\/p>\n<p>set msg = WScript.CreateObject(&#8220;CDO.Message&#8221;)<br \/>\nmsg.From = From<br \/>\nmsg.To = Recipient<br \/>\nmsg.Cc = Cc<br \/>\nmsg.Subject = Subject<br \/>\nmsg.TextBody = Message<br \/>\n&#8216;msg.AddAttachment attachment<br \/>\nmsg.Configuration.Fields (&#8220;http:\/\/schemas.microsoft.com\/cdo\/configuration\/smtpserver&#8221;) = SMTPServer<br \/>\nmsg.Configuration.Fields(&#8220;http:\/\/schemas.microsoft.com\/cdo\/configuration\/sendusing&#8221;) = 2<br \/>\nmsg.Configuration.Fields.Update<br \/>\nmsg.Send<br \/>\nEnd Sub<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"iawp_total_views":3},"question-category":[55],"question_tags":[],"class_list":["post-13532","question","type-question","status-publish","hentry","question-category-programming"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question\/13532","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question"}],"about":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/comments?post=13532"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=13532"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=13532"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=13532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}