{"id":31,"date":"2020-01-03T23:22:51","date_gmt":"2020-01-03T20:22:51","guid":{"rendered":"http:\/\/www.cuneytbayrak.com\/?p=31"},"modified":"2025-02-21T00:42:26","modified_gmt":"2025-02-20T21:42:26","slug":"mssqlden-excele-veri-cekme","status":"publish","type":"post","link":"http:\/\/www.cuneytbayrak.com\/?p=31","title":{"rendered":"MSSQL\u2019den Excele veri \u00e7ekme"},"content":{"rendered":"<p>A\u015fa\u011f\u0131da \u00f6rnek kodlar var. \u0130ncelenirse anla\u015f\u0131lacak mahiyette.<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;vb&quot;,&quot;mime&quot;:&quot;text\/x-vb&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:false,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">Sub DEVIRLER()\r\n \r\nDim cnn As ADODB.Connection\r\nDim rs As ADODB.Recordset\r\nDim strConnectionString As String\r\nDim sorgu As String\r\nDim str As String\r\nDim ws As Worksheet\r\nDim son As Integer\r\n \r\nSet ws = Sheets(\"Sayfa1\")\r\nSet cnn = New ADODB.Connection\r\nSet rs = New ADODB.Recordset\r\nson = ws.Cells(Rows.Count, 1).End(xlUp).Row\r\n \r\nstrConnectionString = \"Provider=SQLOLEDB;Data Source=.....................;Initial Catalog=............;User ID=.............;Password=.....................;\"\r\n \r\nOn Error Resume Next\r\ncnn.ConnectionTimeout = 1\r\ncnn.CommandTimeout = 0\r\ncnn.Open strConnectionString\r\n \r\nFor i = 9 To son - 1\r\nFor j = 1 To 12\r\nrs.Open \"select AVG(\" &amp; ws.Range(\"a\" &amp; i + 1) &amp; \") from PLC19.dbo.MakDevirler where MONTH(Date)=\" &amp; j, cnn\r\nws.Cells(i + 1, j + 1) = CDbl(rs.GetString)\r\nrs.Close\r\nNext\r\nNext\r\n \r\nEnd Sub<\/pre>\n<\/div>\n<p><strong>Not: ADODB.Connection ve\u00a0ADODB.Recordset nesnelerini tan\u0131mlamak i\u00e7in Tools\/References \u2018 dan \u201cMicrosoft ActiveX Data Objects 2.0 Library\u201d referans\u0131n\u0131 projenize eklemeniz gerekir. Yoksa kodlar \u00e7al\u0131\u015fmaz.\u00a0<\/strong><\/p>\n<p>Kolay gele&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A\u015fa\u011f\u0131da \u00f6rnek kodlar var. \u0130ncelenirse anla\u015f\u0131lacak mahiyette. Sub DEVIRLER() Dim cnn As ADODB.Connection Dim rs As ADODB.Recordset Dim strConnectionString As String Dim sorgu As String Dim str As String Dim&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"http:\/\/www.cuneytbayrak.com\/?p=31\">Devam\u0131n\u0131 Oku<span class=\"screen-reader-text\">MSSQL\u2019den Excele veri \u00e7ekme<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":2,"footnotes":""},"categories":[5],"tags":[12],"class_list":["post-31","post","type-post","status-publish","format-standard","hentry","category-excel-vba","tag-sqltoexcel","excerpt"],"_links":{"self":[{"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=\/wp\/v2\/posts\/31","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=31"}],"version-history":[{"count":1,"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=\/wp\/v2\/posts\/31\/revisions"}],"predecessor-version":[{"id":32,"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=\/wp\/v2\/posts\/31\/revisions\/32"}],"wp:attachment":[{"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=31"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=31"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=31"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}