{"id":17598,"date":"2023-08-10T06:00:00","date_gmt":"2023-08-09T21:00:00","guid":{"rendered":"https:\/\/www.muscle-hypertrophy.com\/?p=17598"},"modified":"2023-03-26T13:18:51","modified_gmt":"2023-03-26T04:18:51","slug":"r%e3%81%8b%e3%82%89rodbc%e3%83%91%e3%83%83%e3%82%b1%e3%83%bc%e3%82%b8%e3%82%92%e4%bb%8b%e3%81%97%e3%81%a6sql-server%e3%81%ab%e6%8e%a5%e7%b6%9a%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.muscle-hypertrophy.com\/?p=17598","title":{"rendered":"R\u304b\u3089RODBC\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4ecb\u3057\u3066SQL Server\u306b\u63a5\u7d9a\u3059\u308b"},"content":{"rendered":"\n<p>\u3000R\u304b\u3089SQL Server\u306b\u63a5\u7d9a\u3059\u308b\u65b9\u6cd5\u3092\u8a66\u884c\u932f\u8aa4\u3057\u3066\u3044\u305f\uff0e\u4eca\u56de\u305d\u306e\u65b9\u6cd5\u3092\u898b\u3064\u3051\u305f\u306e\u3067\u5099\u5fd8\u9332\u3068\u3057\u3066\u516c\u958b\u3059\u308b\uff0e<\/p>\n<p><!--more--><\/p>\n<h2>SQL Server\u5074\u306e\u6e96\u5099<\/h2>\n<h3>SQLServerManage15.msc\u3067\u306e\u51e6\u7406<\/h3>\n<p>\u3000\u691c\u7d22\u30bf\u30d6\u306bSQLServerManager15.msc\u3068\u30bf\u30a4\u30d7\u3059\u308b\u3068\u4e0b\u56f3\u306e\u3088\u3046\u306bSQLServer\u69cb\u6210\u30de\u30cd\u30fc\u30b8\u30e3\u304c\u51fa\u73fe\u3059\u308b\u306e\u3067\u30af\u30ea\u30c3\u30af\u3057\u3066\u8d77\u52d5\u3059\u308b\uff0e<\/p>\n<figure id=\"attachment_17599\" aria-describedby=\"caption-attachment-17599\" style=\"width: 732px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.muscle-hypertrophy.com\/wp-content\/uploads\/2023\/03\/00-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-17599\" src=\"https:\/\/www.muscle-hypertrophy.com\/wp-content\/uploads\/2023\/03\/00-1.png\" alt=\"SQLServer\u69cb\u6210\u30de\u30cd\u30fc\u30b8\u30e3\u306e\u8d77\u52d5\" width=\"732\" height=\"420\" srcset=\"https:\/\/www.muscle-hypertrophy.com\/wp-content\/uploads\/2023\/03\/00-1.png 732w, https:\/\/www.muscle-hypertrophy.com\/wp-content\/uploads\/2023\/03\/00-1-300x172.png 300w\" sizes=\"auto, (max-width: 732px) 100vw, 732px\" \/><\/a><figcaption id=\"caption-attachment-17599\" class=\"wp-caption-text\">SQLServer\u69cb\u6210\u30de\u30cd\u30fc\u30b8\u30e3\u306e\u8d77\u52d5<\/figcaption><\/figure>\n<p>\u3000\u300cSQL Server\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u306e\u69cb\u6210\u300d\u3067\u540d\u524d\u4ed8\u304d\u30d1\u30a4\u30d7\u3068TCP\/IP\u3092\u6709\u52b9\u5316\u3059\u308b\uff0e\u305d\u306e\u5f8cSQL Server\u3092\u518d\u8d77\u52d5\u3059\u308b\uff0e<\/p>\n<figure id=\"attachment_17600\" aria-describedby=\"caption-attachment-17600\" style=\"width: 946px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.muscle-hypertrophy.com\/wp-content\/uploads\/2023\/03\/02-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-17600\" src=\"https:\/\/www.muscle-hypertrophy.com\/wp-content\/uploads\/2023\/03\/02-1.png\" alt=\"\u540d\u524d\u4ed8\u304d\u30d1\u30a4\u30d7\u3068TCP\/IP\u3092\u6709\u52b9\u5316\" width=\"946\" height=\"268\" srcset=\"https:\/\/www.muscle-hypertrophy.com\/wp-content\/uploads\/2023\/03\/02-1.png 946w, https:\/\/www.muscle-hypertrophy.com\/wp-content\/uploads\/2023\/03\/02-1-300x85.png 300w, https:\/\/www.muscle-hypertrophy.com\/wp-content\/uploads\/2023\/03\/02-1-768x218.png 768w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/a><figcaption id=\"caption-attachment-17600\" class=\"wp-caption-text\">\u540d\u524d\u4ed8\u304d\u30d1\u30a4\u30d7\u3068TCP\/IP\u3092\u6709\u52b9\u5316<\/figcaption><\/figure>\n<p>\u3000\u300cSQL Server\u306e\u30b5\u30fc\u30d3\u30b9\u300d\u3067\u521d\u671f\u72b6\u614b\u3067\u306f\u505c\u6b62\u3057\u3066\u3044\u308bSQL Server Browser\u3092\u958b\u59cb\u3059\u308b\uff0e<\/p>\n<figure id=\"attachment_17601\" aria-describedby=\"caption-attachment-17601\" style=\"width: 946px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.muscle-hypertrophy.com\/wp-content\/uploads\/2023\/03\/01-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-17601\" src=\"https:\/\/www.muscle-hypertrophy.com\/wp-content\/uploads\/2023\/03\/01-1.png\" alt=\"SQL Server Browser\u3092\u958b\u59cb\" width=\"946\" height=\"268\" srcset=\"https:\/\/www.muscle-hypertrophy.com\/wp-content\/uploads\/2023\/03\/01-1.png 946w, https:\/\/www.muscle-hypertrophy.com\/wp-content\/uploads\/2023\/03\/01-1-300x85.png 300w, https:\/\/www.muscle-hypertrophy.com\/wp-content\/uploads\/2023\/03\/01-1-768x218.png 768w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/a><figcaption id=\"caption-attachment-17601\" class=\"wp-caption-text\">SQL Server Browser\u3092\u958b\u59cb<\/figcaption><\/figure>\n<h2>R\u3067\u306e\u51e6\u7406<\/h2>\n<h3>\u63a5\u7d9a\u6587\u5b57\u5217\u306e\u751f\u6210<\/h3>\n<p>\u3000\u4e0b\u8a18\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3059\u308b\uff0e<\/p>\n<pre>&gt; library(RODBC)\n&gt; db = function(){\n     driver='{SQL Server}'\n     server = 'SERVER_NAME' \n     database = 'HeatStrokeDB' \n     trusted_connection = 'yes'\n     conn=paste('DRIVER=',driver,';SERVER=',server,';DATABASE=',database,';Trusted_Connection=',trusted_connection,';',sep=\"\")\n     cnxn = odbcDriverConnect(conn)\n     return(cnxn)  \n }<\/pre>\n<h3>\u63a5\u7d9a\u306e\u5b9f\u969b<\/h3>\n<p>\u3000\u4e0a\u8a18\u3067\u5b9a\u7fa9\u3057\u305f\u30e6\u30fc\u30b6\u30fc\u5b9a\u7fa9\u95a2\u6570\u3092\u5b9f\u884c\u3057\uff0c\u7d50\u679c\u3092conn\u306b\u683c\u7d0d\u3059\u308b\uff0e\u30b5\u30fc\u30d0\u30fc\u306b\u30ed\u30b0\u30a4\u30f3\u3067\u304d\u306a\u3044\uff0c\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u5230\u9054\u3067\u304d\u306a\u3044\u5834\u5408\u306a\u3069\u306f\u4e0b\u8a18\u30b3\u30fc\u30c9\u304c\u30a8\u30e9\u30fc\u3067\u5931\u6557\u3059\u308b\uff0e<\/p>\n<pre>&gt; conn=db()<\/pre>\n<h3>\u30af\u30a8\u30ea<\/h3>\n<p>\u3000\u30af\u30a8\u30ea\u3092\u7d44\u307f\u7acb\u3066\uff0c\u5b9f\u884c\u3059\u308b\uff0e<\/p>\n<pre>&gt; sqlText=\"SELECT * FROM T_HeatStroke\"\n&gt; dat=sqlQuery(conn, sqlText)<\/pre>\n<p>\u3000\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0dat\u306b\u30af\u30a8\u30ea\u306e\u7d50\u679c\u304c\u683c\u7d0d\u3055\u308c\u305f\uff0e\u6700\u521d\u306e\uff16\u4ef6\u3060\u3051\u62bd\u51fa\u3057\u3066\u307f\u308b\uff0e<\/p>\n<pre>&gt; head(dat)\n        \u65e5\u4ed8 \u90fd\u9053\u5e9c\u770c\u30b3\u30fc\u30c9 \u642c\u9001\u4eba\u54e1\uff08\u8a08\uff09 \u5e74\u9f62\u533a\u5206\uff1a\u65b0\u751f\u5150\n1 2014-08-08             19              3                0\n2 2014-08-08             20              1                0\n3 2014-08-08             21              4                0\n4 2014-08-08             22             10                0\n5 2014-08-08             23             19                0\n6 2014-08-08             24              1                0\n  \u5e74\u9f62\u533a\u5206\uff1a\u4e73\u5e7c\u5150 \u5e74\u9f62\u533a\u5206\uff1a\u5c11\u5e74 \u5e74\u9f62\u533a\u5206\uff1a\u6210\u4eba \u5e74\u9f62\u533a\u5206\uff1a\u9ad8\u9f62\u8005\n1                0              0              1                2\n2                0              0              0                1\n3                0              0              1                3\n4                2              2              0                6\n5                0              5              5                9\n6                0              0              1                0\n  \u5e74\u9f62\u533a\u5206\uff1a\u4e0d\u660e \u50b7\u75c5\u7a0b\u5ea6\uff1a\u6b7b\u4ea1 \u50b7\u75c5\u7a0b\u5ea6\uff1a\u91cd\u75c7 \u50b7\u75c5\u7a0b\u5ea6\uff1a\u4e2d\u7b49\u75c7\n1              0              0              0                3\n2              0              0              0                1\n3              0              0              0                1\n4              0              0              0                1\n5              0              0              0                5\n6              0              0              0                0\n  \u50b7\u75c5\u7a0b\u5ea6\uff1a\u8efd\u75c7 \u50b7\u75c5\u7a0b\u5ea6\uff1a\u305d\u306e\u4ed6\n1              0                0\n2              0                0\n3              3                0\n4              9                0\n5             14                0\n6              1                0<\/pre>\n<h3>\u5207\u65ad<\/h3>\n<p>\u3000\u63a5\u7d9a\u3092\u5207\u65ad\u3059\u308b\u306b\u306f\u4e0b\u8a18\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3059\u308b\uff0e<\/p>\n<pre>&gt; odbcCloseAll()<\/pre>\n<h2>\u307e\u3068\u3081<\/h2>\n<p>\u3000R\u304b\u3089SQL Server\u306b\u63a5\u7d9a\u3059\u308b\u624b\u9806\u3092\u793a\u3057\u305f\uff0eR\u5074\u3067\u306f\u307b\u3068\u3093\u3069\u3059\u308b\u3053\u3068\u304c\u306a\u304f\uff0cSQL Server\u5074\u306e\u6e96\u5099\u304c\u5fc5\u8981\u3060\u3063\u305f\uff0e<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3000R\u304b\u3089SQL Server\u306b\u63a5\u7d9a\u3059\u308b\u65b9\u6cd5\u3092\u8a66\u884c\u932f\u8aa4\u3057\u3066\u3044\u305f\uff0e\u4eca\u56de\u305d\u306e\u65b9\u6cd5\u3092\u898b\u3064\u3051\u305f\u306e\u3067\u5099\u5fd8\u9332\u3068\u3057\u3066\u516c\u958b\u3059\u308b\uff0e<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[7912,13515,8463,13520,13521,13519,677,9695,13511,13518,13516,2740,4254,13514,4252,13512,13513,4250,13517,2498,2783,4295,13305,32,7975,12014,1022,4251],"class_list":{"0":"post-17598","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-technology","7":"tag-database","8":"tag-driver","9":"tag-function","10":"tag-head","11":"tag-odbccloseall","12":"tag-odbcdriverconnect","13":"tag-r","14":"tag-return","15":"tag-rodbc","16":"tag-sep","17":"tag-server","18":"tag-sql-server","19":"tag-sql-server-browser","22":"tag-sqlservermanage15-msc","23":"tag-sqlserver","24":"tag-tcp-ip","25":"tag-trusted_connection","26":"tag-2498","27":"tag-2783","28":"tag-4295","29":"tag-13305","30":"tag-32","31":"tag-7975","32":"tag-12014","33":"tag-1022","34":"tag-4251"},"_links":{"self":[{"href":"https:\/\/www.muscle-hypertrophy.com\/index.php?rest_route=\/wp\/v2\/posts\/17598","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.muscle-hypertrophy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.muscle-hypertrophy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.muscle-hypertrophy.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.muscle-hypertrophy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=17598"}],"version-history":[{"count":7,"href":"https:\/\/www.muscle-hypertrophy.com\/index.php?rest_route=\/wp\/v2\/posts\/17598\/revisions"}],"predecessor-version":[{"id":17608,"href":"https:\/\/www.muscle-hypertrophy.com\/index.php?rest_route=\/wp\/v2\/posts\/17598\/revisions\/17608"}],"wp:attachment":[{"href":"https:\/\/www.muscle-hypertrophy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=17598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.muscle-hypertrophy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=17598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.muscle-hypertrophy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=17598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}