{"id":979,"date":"2014-06-10T19:10:16","date_gmt":"2014-06-10T14:10:16","guid":{"rendered":"http:\/\/www.esearing.com\/v2010\/?p=979"},"modified":"2014-06-10T19:12:17","modified_gmt":"2014-06-10T14:12:17","slug":"coldfusion-working-around-sql-server-key-words","status":"publish","type":"post","link":"https:\/\/www.esearing.com\/v2010\/2014\/06\/coldfusion-working-around-sql-server-key-words\/","title":{"rendered":"Coldfusion working around SQL Server Key words"},"content":{"rendered":"<p>In one of our older database tables we have a field named &#8220;ROLLUP&#8221;.<br \/>\nFor SQL SERVER 2008 this is a reserved word. When writing dynamic SQL with group by statements using the column name &#8220;rollup&#8221; coldfusion will throw a syntax error indicating there is a problem near &#8220;rollup&#8221; or &#8220;,&#8221;.<\/p>\n<p>The solution is to replace the keyword with the keyword in brackets.<\/p>\n<p><strong>Example<\/strong><br \/>\nCFSET mylist = &#8220;rollup,column2,column3,column4&#8221;<br \/>\n* this may come from form elements passed or other selections that make it a dynamic list<\/p>\n<p>Query:<br \/>\nSelect #mylist#<br \/>\n, sum myValue<br \/>\nfrom myTable<br \/>\nwhere 1=1<br \/>\ngroup by #rereplace(mylist, &#8220;rollup&#8221;, &#8220;[rollup]&#8221;, &#8220;1&#8221;)#<br \/>\norder by #mylist#<\/p>\n<p>Yields<br \/>\ngroup by [rollup],column2,column3,column4<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In one of our older database tables we have a field named &#8220;ROLLUP&#8221;. For SQL SERVER 2008 this is a reserved word. When writing dynamic SQL with group by statements using the column name &#8220;rollup&#8221; coldfusion will throw a syntax &hellip; <a href=\"https:\/\/www.esearing.com\/v2010\/2014\/06\/coldfusion-working-around-sql-server-key-words\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,21,24,14],"tags":[],"class_list":["post-979","post","type-post","status-publish","format-standard","hentry","category-coldfusion","category-problems-fixes","category-snippets-quick-code-tips-for-single-elements-attributes-or-details","category-sql"],"_links":{"self":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts\/979","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/comments?post=979"}],"version-history":[{"count":2,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts\/979\/revisions"}],"predecessor-version":[{"id":981,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts\/979\/revisions\/981"}],"wp:attachment":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/media?parent=979"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/categories?post=979"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/tags?post=979"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}