{"id":768,"date":"2014-08-05T11:14:05","date_gmt":"2014-08-05T18:14:05","guid":{"rendered":"http:\/\/deepinthecode.com\/?p=768"},"modified":"2022-12-17T22:46:13","modified_gmt":"2022-12-18T04:46:13","slug":"converting-a-sql-datetime-to-a-javascript-date","status":"publish","type":"post","link":"https:\/\/deepinthecode.com\/2014\/08\/05\/converting-a-sql-datetime-to-a-javascript-date\/","title":{"rendered":"Converting a SQL DATETIME to a JavaScript Date"},"content":{"rendered":"\n<p>It should come as no surprise to anyone who has developed for multiple browsers that each one has its own quirks when it comes to enforcing standards, whether they be CSS, HTML5, or even JavaScript. I have been working on some JavaScript that will take a date (in the DATETIME format) from SQL Server and create a new JavaScript Date object using this date. In doing most web development, I have been using Chrome to test the pages first because I find Chrome&#8217;s developer tools much better than those with Internet Explorer, even though the site will eventually have to be compatible with IE 8+.<\/p>\n\n\n\n<p>Apparently, when taking a <a title=\"MSDN - datetime (Transact-SQL)\" href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/t-sql\/data-types\/datetime-transact-sql?view=sql-server-2017\" target=\"_blank\" rel=\"noopener\">SQL DATETIME<\/a> (which is in the format &#8220;yyyy-mm-dd hh:mm:ss.ms&#8221;) string and creating a new JS Date, Chrome will take it directly, but IE is more strict. IE enforces the JavaScript standard, and simply doesn&#8217;t recognize the DATETIME format as being a valid date. The way I solved this was to parse the DATETIME string by splitting it into arrays and instantiating the <a title=\"W3Schools.com - JavaScript Date Reference\" href=\"https:\/\/www.w3schools.com\/jsref\/jsref_obj_date.asp\" target=\"_blank\" rel=\"noopener\">JS Date object<\/a> by using the &#8220;new Date(year, month, day, hour, minute, second, millisecond)&#8221; syntax.<\/p>\n\n\n\n<p>Below is a function that will take a string in the SQL DATETIME format and will return a JS Date object:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nfunction sqlToJsDate(sqlDate){\n    \/\/sqlDate in SQL DATETIME format (\"yyyy-mm-dd hh:mm:ss.ms\")\n    var sqlDateArr1 = sqlDate.split(\"-\");\n    \/\/format of sqlDateArr1&#x5B;] = &#x5B;'yyyy','mm','dd hh:mm:ms']\n    var sYear = sqlDateArr1&#x5B;0];\n    var sMonth = (Number(sqlDateArr1&#x5B;1]) - 1).toString();\n    var sqlDateArr2 = sqlDateArr1&#x5B;2].split(\" \");\n    \/\/format of sqlDateArr2&#x5B;] = &#x5B;'dd', 'hh:mm:ss.ms']\n    var sDay = sqlDateArr2&#x5B;0];\n    var sqlDateArr3 = sqlDateArr2&#x5B;1].split(\":\");\n    \/\/format of sqlDateArr3&#x5B;] = &#x5B;'hh','mm','ss.ms']\n    var sHour = sqlDateArr3&#x5B;0];\n    var sMinute = sqlDateArr3&#x5B;1];\n    var sqlDateArr4 = sqlDateArr3&#x5B;2].split(\".\");\n    \/\/format of sqlDateArr4&#x5B;] = &#x5B;'ss','ms']\n    var sSecond = sqlDateArr4&#x5B;0];\n    var sMillisecond = sqlDateArr4&#x5B;1];\n\n    return new Date(sYear,sMonth,sDay,sHour,sMinute,sSecond,sMillisecond);\n}\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>It should come as no surprise to anyone who has developed for multiple browsers that each one has its own quirks when it comes to enforcing standards, whether they be CSS, HTML5, or even JavaScript. I have been working on some JavaScript that will take a date (in the DATETIME format) from SQL Server and &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/deepinthecode.com\/2014\/08\/05\/converting-a-sql-datetime-to-a-javascript-date\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Converting a SQL DATETIME to a JavaScript Date&#8221;<\/span><\/a><\/p>\n","protected":false},"author":7,"featured_media":3007,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"Converting a SQL DATETIME to a JavaScript Date - #javascript #js #mssql","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[10,12],"tags":[127],"class_list":["post-768","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","category-ms-sql-server","tag-data-type-conversion"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Converting a SQL DATETIME to a JavaScript Date - Deep in the Code<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/deepinthecode.com\/2014\/08\/05\/converting-a-sql-datetime-to-a-javascript-date\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Converting a SQL DATETIME to a JavaScript Date - Deep in the Code\" \/>\n<meta property=\"og:description\" content=\"It should come as no surprise to anyone who has developed for multiple browsers that each one has its own quirks when it comes to enforcing standards, whether they be CSS, HTML5, or even JavaScript. I have been working on some JavaScript that will take a date (in the DATETIME format) from SQL Server and &hellip; Continue reading &quot;Converting a SQL DATETIME to a JavaScript Date&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/deepinthecode.com\/2014\/08\/05\/converting-a-sql-datetime-to-a-javascript-date\/\" \/>\n<meta property=\"og:site_name\" content=\"Deep in the Code\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/facebook.com\/deepinthecode\" \/>\n<meta property=\"article:author\" content=\"https:\/\/facebook.com\/deepinthecode\" \/>\n<meta property=\"article:published_time\" content=\"2014-08-05T18:14:05+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-12-18T04:46:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/deepinthecode.com\/wp-content\/uploads\/2014\/08\/JavaScript-logo.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1052\" \/>\n\t<meta property=\"og:image:height\" content=\"1052\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"David Young\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@deepinthecode\" \/>\n<meta name=\"twitter:site\" content=\"@deepinthecode\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"David Young\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/deepinthecode.com\\\/2014\\\/08\\\/05\\\/converting-a-sql-datetime-to-a-javascript-date\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/deepinthecode.com\\\/2014\\\/08\\\/05\\\/converting-a-sql-datetime-to-a-javascript-date\\\/\"},\"author\":{\"name\":\"David Young\",\"@id\":\"https:\\\/\\\/deepinthecode.com\\\/#\\\/schema\\\/person\\\/2d8883371cb9a0d1d86ad28246d1b514\"},\"headline\":\"Converting a SQL DATETIME to a JavaScript Date\",\"datePublished\":\"2014-08-05T18:14:05+00:00\",\"dateModified\":\"2022-12-18T04:46:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/deepinthecode.com\\\/2014\\\/08\\\/05\\\/converting-a-sql-datetime-to-a-javascript-date\\\/\"},\"wordCount\":220,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/deepinthecode.com\\\/#\\\/schema\\\/person\\\/2d8883371cb9a0d1d86ad28246d1b514\"},\"image\":{\"@id\":\"https:\\\/\\\/deepinthecode.com\\\/2014\\\/08\\\/05\\\/converting-a-sql-datetime-to-a-javascript-date\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/deepinthecode.com\\\/wp-content\\\/uploads\\\/2014\\\/08\\\/JavaScript-logo.png?fit=1052%2C1052&ssl=1\",\"keywords\":[\"data type conversion\"],\"articleSection\":[\"JavaScript\",\"MS SQL Server\"],\"inLanguage\":\"en\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/deepinthecode.com\\\/2014\\\/08\\\/05\\\/converting-a-sql-datetime-to-a-javascript-date\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/deepinthecode.com\\\/2014\\\/08\\\/05\\\/converting-a-sql-datetime-to-a-javascript-date\\\/\",\"url\":\"https:\\\/\\\/deepinthecode.com\\\/2014\\\/08\\\/05\\\/converting-a-sql-datetime-to-a-javascript-date\\\/\",\"name\":\"Converting a SQL DATETIME to a JavaScript Date - Deep in the Code\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/deepinthecode.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/deepinthecode.com\\\/2014\\\/08\\\/05\\\/converting-a-sql-datetime-to-a-javascript-date\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/deepinthecode.com\\\/2014\\\/08\\\/05\\\/converting-a-sql-datetime-to-a-javascript-date\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/deepinthecode.com\\\/wp-content\\\/uploads\\\/2014\\\/08\\\/JavaScript-logo.png?fit=1052%2C1052&ssl=1\",\"datePublished\":\"2014-08-05T18:14:05+00:00\",\"dateModified\":\"2022-12-18T04:46:13+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/deepinthecode.com\\\/2014\\\/08\\\/05\\\/converting-a-sql-datetime-to-a-javascript-date\\\/#breadcrumb\"},\"inLanguage\":\"en\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/deepinthecode.com\\\/2014\\\/08\\\/05\\\/converting-a-sql-datetime-to-a-javascript-date\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en\",\"@id\":\"https:\\\/\\\/deepinthecode.com\\\/2014\\\/08\\\/05\\\/converting-a-sql-datetime-to-a-javascript-date\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/deepinthecode.com\\\/wp-content\\\/uploads\\\/2014\\\/08\\\/JavaScript-logo.png?fit=1052%2C1052&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/deepinthecode.com\\\/wp-content\\\/uploads\\\/2014\\\/08\\\/JavaScript-logo.png?fit=1052%2C1052&ssl=1\",\"width\":1052,\"height\":1052,\"caption\":\"JavaScript logo\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/deepinthecode.com\\\/2014\\\/08\\\/05\\\/converting-a-sql-datetime-to-a-javascript-date\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/deepinthecode.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Converting a SQL DATETIME to a JavaScript Date\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/deepinthecode.com\\\/#website\",\"url\":\"https:\\\/\\\/deepinthecode.com\\\/\",\"name\":\"Deep in the Code\",\"description\":\"Adventures in Software Development ... by David Young\",\"publisher\":{\"@id\":\"https:\\\/\\\/deepinthecode.com\\\/#\\\/schema\\\/person\\\/2d8883371cb9a0d1d86ad28246d1b514\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/deepinthecode.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/deepinthecode.com\\\/#\\\/schema\\\/person\\\/2d8883371cb9a0d1d86ad28246d1b514\",\"name\":\"David Young\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en\",\"@id\":\"https:\\\/\\\/i0.wp.com\\\/deepinthecode.com\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/monolith2.png?fit=902%2C559&ssl=1\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/deepinthecode.com\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/monolith2.png?fit=902%2C559&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/deepinthecode.com\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/monolith2.png?fit=902%2C559&ssl=1\",\"width\":902,\"height\":559,\"caption\":\"David Young\"},\"logo\":{\"@id\":\"https:\\\/\\\/i0.wp.com\\\/deepinthecode.com\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/monolith2.png?fit=902%2C559&ssl=1\"},\"description\":\"I solve problems. Solutions Architect \\\/ Senior Software Engineer \\\/ Business Analyst \\\/ Full-Stack Developer \\\/ Data Scientist\\\/ IT Generalist\",\"sameAs\":[\"https:\\\/\\\/deepinthecode.com\",\"https:\\\/\\\/facebook.com\\\/deepinthecode\",\"https:\\\/\\\/instagram.com\\\/deepinthecode\",\"https:\\\/\\\/linkedin.com\\\/in\\\/deepinthecode\",\"https:\\\/\\\/x.com\\\/deepinthecode\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Converting a SQL DATETIME to a JavaScript Date - Deep in the Code","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/deepinthecode.com\/2014\/08\/05\/converting-a-sql-datetime-to-a-javascript-date\/","og_locale":"en_US","og_type":"article","og_title":"Converting a SQL DATETIME to a JavaScript Date - Deep in the Code","og_description":"It should come as no surprise to anyone who has developed for multiple browsers that each one has its own quirks when it comes to enforcing standards, whether they be CSS, HTML5, or even JavaScript. I have been working on some JavaScript that will take a date (in the DATETIME format) from SQL Server and &hellip; Continue reading \"Converting a SQL DATETIME to a JavaScript Date\"","og_url":"https:\/\/deepinthecode.com\/2014\/08\/05\/converting-a-sql-datetime-to-a-javascript-date\/","og_site_name":"Deep in the Code","article_publisher":"https:\/\/facebook.com\/deepinthecode","article_author":"https:\/\/facebook.com\/deepinthecode","article_published_time":"2014-08-05T18:14:05+00:00","article_modified_time":"2022-12-18T04:46:13+00:00","og_image":[{"width":1052,"height":1052,"url":"https:\/\/deepinthecode.com\/wp-content\/uploads\/2014\/08\/JavaScript-logo.png","type":"image\/png"}],"author":"David Young","twitter_card":"summary_large_image","twitter_creator":"@deepinthecode","twitter_site":"@deepinthecode","twitter_misc":{"Written by":"David Young","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/deepinthecode.com\/2014\/08\/05\/converting-a-sql-datetime-to-a-javascript-date\/#article","isPartOf":{"@id":"https:\/\/deepinthecode.com\/2014\/08\/05\/converting-a-sql-datetime-to-a-javascript-date\/"},"author":{"name":"David Young","@id":"https:\/\/deepinthecode.com\/#\/schema\/person\/2d8883371cb9a0d1d86ad28246d1b514"},"headline":"Converting a SQL DATETIME to a JavaScript Date","datePublished":"2014-08-05T18:14:05+00:00","dateModified":"2022-12-18T04:46:13+00:00","mainEntityOfPage":{"@id":"https:\/\/deepinthecode.com\/2014\/08\/05\/converting-a-sql-datetime-to-a-javascript-date\/"},"wordCount":220,"commentCount":0,"publisher":{"@id":"https:\/\/deepinthecode.com\/#\/schema\/person\/2d8883371cb9a0d1d86ad28246d1b514"},"image":{"@id":"https:\/\/deepinthecode.com\/2014\/08\/05\/converting-a-sql-datetime-to-a-javascript-date\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/deepinthecode.com\/wp-content\/uploads\/2014\/08\/JavaScript-logo.png?fit=1052%2C1052&ssl=1","keywords":["data type conversion"],"articleSection":["JavaScript","MS SQL Server"],"inLanguage":"en","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/deepinthecode.com\/2014\/08\/05\/converting-a-sql-datetime-to-a-javascript-date\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/deepinthecode.com\/2014\/08\/05\/converting-a-sql-datetime-to-a-javascript-date\/","url":"https:\/\/deepinthecode.com\/2014\/08\/05\/converting-a-sql-datetime-to-a-javascript-date\/","name":"Converting a SQL DATETIME to a JavaScript Date - Deep in the Code","isPartOf":{"@id":"https:\/\/deepinthecode.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/deepinthecode.com\/2014\/08\/05\/converting-a-sql-datetime-to-a-javascript-date\/#primaryimage"},"image":{"@id":"https:\/\/deepinthecode.com\/2014\/08\/05\/converting-a-sql-datetime-to-a-javascript-date\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/deepinthecode.com\/wp-content\/uploads\/2014\/08\/JavaScript-logo.png?fit=1052%2C1052&ssl=1","datePublished":"2014-08-05T18:14:05+00:00","dateModified":"2022-12-18T04:46:13+00:00","breadcrumb":{"@id":"https:\/\/deepinthecode.com\/2014\/08\/05\/converting-a-sql-datetime-to-a-javascript-date\/#breadcrumb"},"inLanguage":"en","potentialAction":[{"@type":"ReadAction","target":["https:\/\/deepinthecode.com\/2014\/08\/05\/converting-a-sql-datetime-to-a-javascript-date\/"]}]},{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/deepinthecode.com\/2014\/08\/05\/converting-a-sql-datetime-to-a-javascript-date\/#primaryimage","url":"https:\/\/i0.wp.com\/deepinthecode.com\/wp-content\/uploads\/2014\/08\/JavaScript-logo.png?fit=1052%2C1052&ssl=1","contentUrl":"https:\/\/i0.wp.com\/deepinthecode.com\/wp-content\/uploads\/2014\/08\/JavaScript-logo.png?fit=1052%2C1052&ssl=1","width":1052,"height":1052,"caption":"JavaScript logo"},{"@type":"BreadcrumbList","@id":"https:\/\/deepinthecode.com\/2014\/08\/05\/converting-a-sql-datetime-to-a-javascript-date\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/deepinthecode.com\/"},{"@type":"ListItem","position":2,"name":"Converting a SQL DATETIME to a JavaScript Date"}]},{"@type":"WebSite","@id":"https:\/\/deepinthecode.com\/#website","url":"https:\/\/deepinthecode.com\/","name":"Deep in the Code","description":"Adventures in Software Development ... by David Young","publisher":{"@id":"https:\/\/deepinthecode.com\/#\/schema\/person\/2d8883371cb9a0d1d86ad28246d1b514"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/deepinthecode.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en"},{"@type":["Person","Organization"],"@id":"https:\/\/deepinthecode.com\/#\/schema\/person\/2d8883371cb9a0d1d86ad28246d1b514","name":"David Young","image":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/i0.wp.com\/deepinthecode.com\/wp-content\/uploads\/2022\/07\/monolith2.png?fit=902%2C559&ssl=1","url":"https:\/\/i0.wp.com\/deepinthecode.com\/wp-content\/uploads\/2022\/07\/monolith2.png?fit=902%2C559&ssl=1","contentUrl":"https:\/\/i0.wp.com\/deepinthecode.com\/wp-content\/uploads\/2022\/07\/monolith2.png?fit=902%2C559&ssl=1","width":902,"height":559,"caption":"David Young"},"logo":{"@id":"https:\/\/i0.wp.com\/deepinthecode.com\/wp-content\/uploads\/2022\/07\/monolith2.png?fit=902%2C559&ssl=1"},"description":"I solve problems. Solutions Architect \/ Senior Software Engineer \/ Business Analyst \/ Full-Stack Developer \/ Data Scientist\/ IT Generalist","sameAs":["https:\/\/deepinthecode.com","https:\/\/facebook.com\/deepinthecode","https:\/\/instagram.com\/deepinthecode","https:\/\/linkedin.com\/in\/deepinthecode","https:\/\/x.com\/deepinthecode"]}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/deepinthecode.com\/wp-content\/uploads\/2014\/08\/JavaScript-logo.png?fit=1052%2C1052&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3J1Ni-co","jetpack-related-posts":[{"id":292,"url":"https:\/\/deepinthecode.com\/2013\/05\/29\/converting-a-sql-server-table-into-a-json-object-using-a-stored-procedure\/","url_meta":{"origin":768,"position":0},"title":"Converting a SQL Server Table into a JavaScript Object Using a Stored Procedure","author":"David Young","date":"2013.05.29","format":false,"excerpt":"A couple of weeks ago, I attended Houston's first Open Innovation Hackathon and joined the team that had the goal of redeveloping the City of Houston City-Wide Fee Schedule. The current fee schedule is an ASP.NET Web application with a SQL Server back end. At the end of the hackathon,\u2026","rel":"","context":"In &quot;JavaScript&quot;","block_context":{"text":"JavaScript","link":"https:\/\/deepinthecode.com\/category\/javascript\/"},"img":{"alt_text":"JSON logo","src":"https:\/\/i0.wp.com\/deepinthecode.com\/wp-content\/uploads\/2013\/05\/JSON.png?fit=512%2C512&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":229,"url":"https:\/\/deepinthecode.com\/2013\/04\/03\/moving-data-from-the-image-datatype-to-varbinarymax-from-a-sql-server-2000-instance\/","url_meta":{"origin":768,"position":1},"title":"Moving Data from the IMAGE Datatype to VARBINARY(MAX) from a SQL Server 2000 Instance","author":"David Young","date":"2013.04.03","format":false,"excerpt":"I am in the process of writing scripts to move data from a SQL 2000 database into a different database running on SQL 2008. I had set up a linked server from the SQL 2k server to begin this process, and about 90% of the data could be moved. \u00a0One\u2026","rel":"","context":"In &quot;MS SQL Server&quot;","block_context":{"text":"MS SQL Server","link":"https:\/\/deepinthecode.com\/category\/ms-sql-server\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":334,"url":"https:\/\/deepinthecode.com\/2013\/07\/04\/converting-a-sql-table-to-json-objects-using-the-asp-net-mvc-web-api\/","url_meta":{"origin":768,"position":2},"title":"Converting a SQL Table to JavaScript Objects Using the ASP.NET MVC Web API","author":"David Young","date":"2013.07.04","format":false,"excerpt":"Happy Independence Day! Here I will describe an alternative to an earlier post that described using a SQL stored procedure to convert a SQL table into a JavaScript object. One of the comments left on that post made me wonder why someone would not want to use the stored procedure\u2026","rel":"","context":"In &quot;ASP.NET&quot;","block_context":{"text":"ASP.NET","link":"https:\/\/deepinthecode.com\/category\/asp-net\/"},"img":{"alt_text":"ASP.NET MVC Web API logo","src":"https:\/\/i0.wp.com\/deepinthecode.com\/wp-content\/uploads\/2013\/06\/ASPNET-MVC-WEB-API.jpg?fit=629%2C419&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/deepinthecode.com\/wp-content\/uploads\/2013\/06\/ASPNET-MVC-WEB-API.jpg?fit=629%2C419&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/deepinthecode.com\/wp-content\/uploads\/2013\/06\/ASPNET-MVC-WEB-API.jpg?fit=629%2C419&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":1570,"url":"https:\/\/deepinthecode.com\/2017\/08\/14\/deleting-duplicate-rows-in-a-sql-server-table-using-a-cte\/","url_meta":{"origin":768,"position":3},"title":"Deleting Duplicate Rows in a SQL Server Table Using a CTE","author":"David Young","date":"2017.08.14","format":false,"excerpt":"Finding duplicate rows in a table is quite simple. Deleting only the duplicates - as opposed to deleting all rows that have duplicates - is a bit more complicated. I have a table variable called \"@Readings\" with the following schema: DECLARE @Readings TABLE ( TagName VARCHAR(100), ScanTime DATETIME, TagValue NUMERIC(10,3)\u2026","rel":"","context":"In &quot;MS SQL Server&quot;","block_context":{"text":"MS SQL Server","link":"https:\/\/deepinthecode.com\/category\/ms-sql-server\/"},"img":{"alt_text":"CTE example","src":"https:\/\/i0.wp.com\/deepinthecode.com\/wp-content\/uploads\/2017\/08\/CTEexample.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/deepinthecode.com\/wp-content\/uploads\/2017\/08\/CTEexample.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/deepinthecode.com\/wp-content\/uploads\/2017\/08\/CTEexample.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":2190,"url":"https:\/\/deepinthecode.com\/2019\/02\/28\/sql-server-script-to-create-insert-statements\/","url_meta":{"origin":768,"position":4},"title":"SQL Server Script to Create INSERT Statements","author":"David Young","date":"2019.02.28","format":false,"excerpt":"Though you can generate INSERT statements using SQL Server Management Services if the Generate Scripts functionality is enabled, this script may help in cases when it is not. USE DatabaseName GO SET NOCOUNT ON DECLARE @TableName VARCHAR(255) DECLARE @IndividualInserts BIT SET @TableName = 'TableName' SET @IndividualInserts = 0 DECLARE @TableStructure\u2026","rel":"","context":"In &quot;MS SQL Server&quot;","block_context":{"text":"MS SQL Server","link":"https:\/\/deepinthecode.com\/category\/ms-sql-server\/"},"img":{"alt_text":"Microsoft SQL Server logo","src":"https:\/\/i0.wp.com\/deepinthecode.com\/wp-content\/uploads\/2019\/01\/sqlserverlogo.png?fit=1200%2C306&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/deepinthecode.com\/wp-content\/uploads\/2019\/01\/sqlserverlogo.png?fit=1200%2C306&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/deepinthecode.com\/wp-content\/uploads\/2019\/01\/sqlserverlogo.png?fit=1200%2C306&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/deepinthecode.com\/wp-content\/uploads\/2019\/01\/sqlserverlogo.png?fit=1200%2C306&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/deepinthecode.com\/wp-content\/uploads\/2019\/01\/sqlserverlogo.png?fit=1200%2C306&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":262,"url":"https:\/\/deepinthecode.com\/2013\/04\/18\/do-we-have-to-use-a-sql-cursor\/","url_meta":{"origin":768,"position":5},"title":"Do We Have to Use a SQL Cursor?","author":"David Young","date":"2013.04.18","format":false,"excerpt":"In migrating data from a legacy budget application to its replacement, my requirement was to take the first and last years in a budget from the old application and update the corresponding table in the \"new\" app table with those dates as the beginning and ending of the project. One\u2026","rel":"","context":"In &quot;MS SQL Server&quot;","block_context":{"text":"MS SQL Server","link":"https:\/\/deepinthecode.com\/category\/ms-sql-server\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/deepinthecode.com\/wp-json\/wp\/v2\/posts\/768","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/deepinthecode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/deepinthecode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/deepinthecode.com\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/deepinthecode.com\/wp-json\/wp\/v2\/comments?post=768"}],"version-history":[{"count":7,"href":"https:\/\/deepinthecode.com\/wp-json\/wp\/v2\/posts\/768\/revisions"}],"predecessor-version":[{"id":3009,"href":"https:\/\/deepinthecode.com\/wp-json\/wp\/v2\/posts\/768\/revisions\/3009"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/deepinthecode.com\/wp-json\/wp\/v2\/media\/3007"}],"wp:attachment":[{"href":"https:\/\/deepinthecode.com\/wp-json\/wp\/v2\/media?parent=768"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/deepinthecode.com\/wp-json\/wp\/v2\/categories?post=768"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/deepinthecode.com\/wp-json\/wp\/v2\/tags?post=768"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}