{"id":24797,"date":"2022-12-05T20:25:16","date_gmt":"2022-12-05T14:55:16","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/"},"modified":"2022-12-05T20:25:16","modified_gmt":"2022-12-05T14:55:16","slug":"solved-why-is-this-cursor-giving-an-error","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/","title":{"rendered":"[Solved] Why is this cursor giving an error?"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-13882453\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"13882453\" data-parentid=\"13882303\" data-score=\"2\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>Given an input XML, you can use this simple XQuery statement to &#8220;shred&#8221; the XML into relational rows and columns &#8211; just do a simple <code>INSERT INTO .....<\/code> and you&#8217;re done. No messy cursor nor <code>OPENXML<\/code> stuff needed&#8230;<\/p>\n<pre><code>DECLARE @input XML = '&lt;Salaray&gt;\n  &lt;TransactionSalary \n    EmpSL=\"2\" Basic=\"9860\" Grad_pay=\"4100.00\" DA=\"6282.00\" HRA=\"2094\" MA=\"300.00\" Ptax=\"150.00\" pf=\"2000\" \n    Itax=\"0.00\" LIC=\"0.00\" Month_Of=\"14\/Dec\/2012\" \/&gt; \n  &lt;TransactionSalary EmpSL=\"1\" Basic=\"12560\" Grad_pay=\"4800.00\" DA=\"7812.00\" HRA=\"2604.00\" MA=\"300\" Ptax=\"150.00\" pf=\"2000\" Itax=\"0.00\" LIC=\"0.00\" Month_Of=\"14\/Dec\/2012\" \/&gt; \n  &lt;TransactionSalary EmpSL=\"4\" Basic=\"11850\" Grad_pay=\"4800.00\" DA=\"7493.00\" HRA=\"2498.00\" MA=\"300\" Ptax=\"150.00\" pf=\"2000\" Itax=\"0.00\" LIC=\"0.00\" Month_Of=\"14\/Dec\/2012\" \/&gt; \n  &lt;\/Salaray&gt;'\n\n\/* just add this INSERT INTO statement when you're confident the SELECT returns the right data! \nINSERT INTO [Monthly_Salary_Statement]([Emp_SL], [Basic], [Grad_pay], [DA], [HRA], [MA], [Ptax], [Itax], [pf],  [LIC], [Month_Of])\n*\/\n SELECT\n    Emp_SL = XTbl.TSal.value('@EmpSL', 'int'),\n    [Basic] = XTbl.TSal.value('@Basic', 'decimal(10,2)'),\n    Grad_pay = XTbl.TSal.value('@Grad_pay', 'decimal(6,2)'),\n    DA = XTbl.TSal.value('@DA', 'decimal(6,2)'),\n    HRA = XTbl.TSal.value('@HRA', 'decimal(6,2)'),\n    MA = XTbl.TSal.value('@MA', 'decimal(6,2)'),\n    Ptax = XTbl.TSal.value('@Ptax', 'decimal(6,2)'),\n    Itax = XTbl.TSal.value('@Itax', 'decimal(6,2)'),\n    pf = XTbl.TSal.value('@pf', 'decimal(6,2)'),\n    LIC = XTbl.TSal.value('@LIC', 'decimal(6,2)'),\n    Month_Of = XTbl.TSal.value('@Month_Of', 'datetime')\n  FROM\n    @input.nodes('\/Salaray\/TransactionSalary') AS XTbl(TSal)\n<\/code><\/pre>\n<p>Also: mind you, you have values like <code>12560<\/code> for your <code>Basic<\/code> attribute &#8211; those will <strong>NOT<\/strong> fit into a <code>decimal(6,2)<\/code> &#8211; that&#8217;s 6 digits total, 2 of which after the comma &#8211; which also means: only 4 digits <em>before<\/em> the comma &#8211; not enough to hold <code>12560<\/code>. I used <code>decimal(10,2)<\/code> instead &#8211; that works.<\/p>\n<p>Gives me output of:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/12\/Solved-Why-is-this-cursor-giving-an-error.png\" alt=\"enter image description here\"><\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\"><\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Why is this cursor giving an error? <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] Given an input XML, you can use this simple XQuery statement to &#8220;shred&#8221; the XML into relational rows and columns &#8211; just do a simple INSERT INTO &#8230;.. and you&#8217;re done. No messy cursor nor OPENXML stuff needed&#8230; DECLARE @input XML = &#8216;&lt;Salaray&gt; &lt;TransactionSalary EmpSL=&#8221;2&#8243; Basic=&#8221;9860&#8243; Grad_pay=&#8221;4100.00&#8243; DA=&#8221;6282.00&#8243; HRA=&#8221;2094&#8243; MA=&#8221;300.00&#8243; Ptax=&#8221;150.00&#8243; pf=&#8221;2000&#8243; Itax=&#8221;0.00&#8243; LIC=&#8221;0.00&#8243; &#8230; <a title=\"[Solved] Why is this cursor giving an error?\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/\" aria-label=\"More on [Solved] Why is this cursor giving an error?\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[500,1872,577],"class_list":["post-24797","post","type-post","status-publish","format-standard","hentry","category-solved","tag-sql-server","tag-stored-procedures","tag-xml"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Why is this cursor giving an error? - JassWeb<\/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:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Why is this cursor giving an error? - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] Given an input XML, you can use this simple XQuery statement to &#8220;shred&#8221; the XML into relational rows and columns &#8211; just do a simple INSERT INTO ..... and you&#8217;re done. No messy cursor nor OPENXML stuff needed&#8230; DECLARE @input XML = &#039;&lt;Salaray&gt; &lt;TransactionSalary EmpSL=&quot;2&quot; Basic=&quot;9860&quot; Grad_pay=&quot;4100.00&quot; DA=&quot;6282.00&quot; HRA=&quot;2094&quot; MA=&quot;300.00&quot; Ptax=&quot;150.00&quot; pf=&quot;2000&quot; Itax=&quot;0.00&quot; LIC=&quot;0.00&quot; ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-12-05T14:55:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/12\/Solved-Why-is-this-cursor-giving-an-error.png\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Why is this cursor giving an error?\",\"datePublished\":\"2022-12-05T14:55:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/\"},\"wordCount\":104,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/12\/Solved-Why-is-this-cursor-giving-an-error.png\",\"keywords\":[\"sql-server\",\"stored-procedures\",\"xml\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/\",\"name\":\"[Solved] Why is this cursor giving an error? - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/12\/Solved-Why-is-this-cursor-giving-an-error.png\",\"datePublished\":\"2022-12-05T14:55:16+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/#primaryimage\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/12\/Solved-Why-is-this-cursor-giving-an-error.png\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/12\/Solved-Why-is-this-cursor-giving-an-error.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Why is this cursor giving an error?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Why is this cursor giving an error? - JassWeb","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:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Why is this cursor giving an error? - JassWeb","og_description":"[ad_1] Given an input XML, you can use this simple XQuery statement to &#8220;shred&#8221; the XML into relational rows and columns &#8211; just do a simple INSERT INTO ..... and you&#8217;re done. No messy cursor nor OPENXML stuff needed&#8230; DECLARE @input XML = '&lt;Salaray&gt; &lt;TransactionSalary EmpSL=\"2\" Basic=\"9860\" Grad_pay=\"4100.00\" DA=\"6282.00\" HRA=\"2094\" MA=\"300.00\" Ptax=\"150.00\" pf=\"2000\" Itax=\"0.00\" LIC=\"0.00\" ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/","og_site_name":"JassWeb","article_published_time":"2022-12-05T14:55:16+00:00","og_image":[{"url":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/12\/Solved-Why-is-this-cursor-giving-an-error.png","type":"","width":"","height":""}],"author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Why is this cursor giving an error?","datePublished":"2022-12-05T14:55:16+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/"},"wordCount":104,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"image":{"@id":"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/#primaryimage"},"thumbnailUrl":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/12\/Solved-Why-is-this-cursor-giving-an-error.png","keywords":["sql-server","stored-procedures","xml"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/","url":"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/","name":"[Solved] Why is this cursor giving an error? - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/#primaryimage"},"image":{"@id":"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/#primaryimage"},"thumbnailUrl":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/12\/Solved-Why-is-this-cursor-giving-an-error.png","datePublished":"2022-12-05T14:55:16+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/#primaryimage","url":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/12\/Solved-Why-is-this-cursor-giving-an-error.png","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/12\/Solved-Why-is-this-cursor-giving-an-error.png"},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-why-is-this-cursor-giving-an-error\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Why is this cursor giving an error?"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/24797","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=24797"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/24797\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=24797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=24797"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=24797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}