<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7204472375574233207</id><updated>2024-08-21T17:44:20.882-07:00</updated><category term="Sql"/><category term="Sql Server"/><category term="Oracle"/><category term="Sql Server 2008"/><category term="C#"/><category term="Ms Access"/><category term="Mysql"/><category term="Tsql"/><category term="Database"/><category term="Sqlite"/><category term="Xml"/><category term="Cursor"/><category term="Entity Framework"/><category term="Java"/><category term="Postgresql"/><category term="Sql Server 2008 R2"/><category term="Sqlxml"/><category term="Stored Procedures"/><category term="Xquery"/><category term="Ado"/><category term="Alter Table"/><category term="Android"/><category term="Asp.net"/><category term="Authentication"/><category term="C"/><category term="Calendar"/><category term="Circular Reference"/><category term="Class"/><category term="Cocoa Touch"/><category term="Columnsorting"/><category term="Concat"/><category term="Concatenation"/><category term="Create Table"/><category term="Currency"/><category term="Database Project"/><category term="Datagridview"/><category term="Date Range"/><category term="Datetime Format"/><category term="Delphi"/><category term="Delphi 5"/><category term="Excel"/><category term="Freetext"/><category term="Full Text Search"/><category term="Greatest N Per Group"/><category term="Hibernate"/><category term="Hive"/><category term="Inner Join"/><category term="Linked Server"/><category term="Linq"/><category term="Linq To Sql"/><category term="Methods"/><category term="Moss"/><category term="Mysql Error 1267"/><category term="Netbeans"/><category term="Oracle10g"/><category term="Oracle11g"/><category term="Owner"/><category term="Performance"/><category term="Plsql"/><category term="Postgresql 10"/><category term="Python"/><category term="Regex"/><category term="Roles"/><category term="Security"/><category term="Sharepoint"/><category term="Sharepoint 2007"/><category term="Sp Executesql"/><category term="Sql Delete"/><category term="Sql Execution Plan"/><category term="Sql Insert"/><category term="Sql Order By"/><category term="Sql Server 2005"/><category term="Sql Server Mars"/><category term="Sqlalchemy"/><category term="Synonym"/><category term="Timestamp"/><category term="Unit Testing"/><category term="Vb.net"/><category term="Vb6"/><category term="Vba"/><category term="Visual Studio 2012"/><title type='text'>supers-affiliate</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='https://supers-affiliate.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default'/><link rel='alternate' type='text/html' href='https://supers-affiliate.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default?start-index=26&amp;max-results=25'/><author><name>Blake Hickle</name><uri>http://www.blogger.com/profile/04290019036198769750</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>48</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7204472375574233207.post-8398491962910577512</id><published>2024-08-21T17:43:00.001-07:00</published><updated>2024-08-21T17:43:47.996-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><category scheme="http://www.blogger.com/atom/ns#" term="Tsql"/><title type='text'>How To Convert Some Records Ins Sql Server</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I have a column with values like this: ## codel ## 1-829549-305-117 1-1196585-305-119 119.305.1983984.1 // this record 1-224594-305-121 1-1999987-305-121 122.306.113416.1 // this r&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Just replace the &lt;code&gt;-&lt;/code&gt; with &lt;code&gt;.&lt;/code&gt;, because &lt;code&gt;PARSENAME()&lt;/code&gt; works only with &lt;code&gt;&#39;.&#39;&lt;/code&gt;, not &lt;code&gt;&#39;-&#39;&lt;/code&gt;&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_5&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;WITH&lt;/span&gt; TBL &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt;
(
  &lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;1-829549-305-117&#39;&lt;/span&gt; Str
  &lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;1-1196585-305-119&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;119.305.1983984.1&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;1-224594-305-121&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;1-1999987-305-121&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;122.306.113416.1&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;1-158059-305-122&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;1-1083888-305-126&#39;&lt;/span&gt;
),
CTE &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt;
(
  &lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; Str,
         &lt;span class=&quot;hljs-keyword&quot;&gt;CASE&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;WHEN&lt;/span&gt; CHARINDEX(&lt;span class=&quot;hljs-string&quot;&gt;&#39;.&#39;&lt;/span&gt;, Str) &lt;span class=&quot;hljs-operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;THEN&lt;/span&gt;
                   Str
              &lt;span class=&quot;hljs-keyword&quot;&gt;ELSE&lt;/span&gt; REPLACE(Str, &lt;span class=&quot;hljs-string&quot;&gt;&#39;-&#39;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#39;.&#39;&lt;/span&gt;)
         &lt;span class=&quot;hljs-keyword&quot;&gt;END&lt;/span&gt; Str1
         ,
         &lt;span class=&quot;hljs-keyword&quot;&gt;CASE&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;WHEN&lt;/span&gt; CHARINDEX(&lt;span class=&quot;hljs-string&quot;&gt;&#39;.&#39;&lt;/span&gt;, Str) &lt;span class=&quot;hljs-operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;THEN&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;.&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;ELSE&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;-&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;END&lt;/span&gt; Sep
  &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; TBL
)
&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; Str,
       CONCAT(PARSENAME(Str1,&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;), Sep,
              PARSENAME(Str1,&lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;), Sep,
              PARSENAME(Str1,&lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;), Sep,
              PARSENAME(Str1,&lt;span class=&quot;hljs-number&quot;&gt;4&lt;/span&gt;)
              ) &lt;span class=&quot;hljs-keyword&quot;&gt;Result&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; CTE;
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_5&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Returns:&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_6&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;-------------------+-------------------+&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;        Str        &lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Result&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;-------------------+-------------------+&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-1083888&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-305&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-126&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;126&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-305&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-1083888&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-1&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-1196585&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-305&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-119&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;119&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-305&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-1196585&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-1&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-158059&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-305&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-122&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;122&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-305&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-158059&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-1&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;119.305&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;.1983984&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;.1&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1.1983984&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;.305&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;.119&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-1999987&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-305&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-121&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;121&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-305&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-1999987&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-1&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;122.306&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;.113416&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;.1&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1.113416&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;.306&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;.122&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-224594&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-305&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-121&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;121&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-305&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-224594&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-1&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-829549&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-305&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-117&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;117&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-305&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-829549&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-1&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;-------------------+-------------------+&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_6&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://dbfiddle.uk/?rdbms=sqlserver_2017&amp;amp;fiddle=33d3f4c45592e7fb76eb5615ae3b4c0b&quot;&gt;Live Demo&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;hr&gt;&lt;p&gt;If you have SQL Server 2017, then you can use &lt;strong&gt;&lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://docs.microsoft.com/en-us/sql/t-sql/functions/concat-ws-transact-sql?view=sql-server-2017&quot;&gt;&lt;code&gt;CONCAT_WS()&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; as&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_8&quot; class=&quot;hljs language-scss&quot;&gt;SELECT Str,
       &lt;span class=&quot;hljs-built_in&quot;&gt;CONCAT_WS&lt;/span&gt;(Sep, 
              PARSENAME(Str1,&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;), 
              &lt;span class=&quot;hljs-built_in&quot;&gt;PARSENAME&lt;/span&gt;(Str1,&lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;), 
              &lt;span class=&quot;hljs-built_in&quot;&gt;PARSENAME&lt;/span&gt;(Str1,&lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;), 
              &lt;span class=&quot;hljs-built_in&quot;&gt;PARSENAME&lt;/span&gt;(Str1,&lt;span class=&quot;hljs-number&quot;&gt;4&lt;/span&gt;)
              ) Result

FROM CTE;
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_8&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;hr&gt;&lt;p&gt;If you want the separator to be always &lt;code&gt;&#39;-&#39;&lt;/code&gt;then no need to &lt;code&gt;Sep&lt;/code&gt;, just directly &lt;code&gt;&#39;-&#39;&lt;/code&gt;&lt;/p&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;You just need to add this code&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_12&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; [Codel],
&lt;span class=&quot;hljs-keyword&quot;&gt;case&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;WHEN&lt;/span&gt;  (CHARINDEX(&lt;span class=&quot;hljs-string&quot;&gt;&#39;.&#39;&lt;/span&gt;,[Codel]) &lt;span class=&quot;hljs-operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot;&gt;then&lt;/span&gt; 

    CONCAT(PARSENAME([Codel], &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;), &lt;span class=&quot;hljs-string&quot;&gt;&#39;-&#39;&lt;/span&gt;,
           PARSENAME([Codel], &lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;), &lt;span class=&quot;hljs-string&quot;&gt;&#39;-&#39;&lt;/span&gt;,
           PARSENAME([Codel], &lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;), &lt;span class=&quot;hljs-string&quot;&gt;&#39;-&#39;&lt;/span&gt;,
           PARSENAME([Codel], &lt;span class=&quot;hljs-number&quot;&gt;4&lt;/span&gt;))  
           &lt;span class=&quot;hljs-keyword&quot;&gt;else&lt;/span&gt; [Codel] &lt;span class=&quot;hljs-keyword&quot;&gt;end&lt;/span&gt;
            true_template

  &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; [TestDB].[dbo].[CodelTbl]
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_12&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_3&quot;&gt;Solution 3:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Here is how you can split your string based on &quot;.&quot; and use the values separately:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_13&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;table&lt;/span&gt; #temp (rn &lt;span class=&quot;hljs-type&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;identity&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;), num &lt;span class=&quot;hljs-type&quot;&gt;int&lt;/span&gt;)

&lt;span class=&quot;hljs-keyword&quot;&gt;Declare&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@products&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;varchar&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot;&gt;200&lt;/span&gt;) &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;119.305.1983984.1&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Declare&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@individual&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;varchar&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot;&gt;20&lt;/span&gt;) &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;null&lt;/span&gt;

WHILE LEN(&lt;span class=&quot;hljs-variable&quot;&gt;@products&lt;/span&gt;) &lt;span class=&quot;hljs-operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;BEGIN&lt;/span&gt;
    IF PATINDEX(&lt;span class=&quot;hljs-string&quot;&gt;&#39;%.%&#39;&lt;/span&gt;, &lt;span class=&quot;hljs-variable&quot;&gt;@products&lt;/span&gt;) &lt;span class=&quot;hljs-operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;BEGIN&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SET&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@individual&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;SUBSTRING&lt;/span&gt;(&lt;span class=&quot;hljs-variable&quot;&gt;@products&lt;/span&gt;,
                                    &lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;,
                                    PATINDEX(&lt;span class=&quot;hljs-string&quot;&gt;&#39;%.%&#39;&lt;/span&gt;, &lt;span class=&quot;hljs-variable&quot;&gt;@products&lt;/span&gt;))
        &lt;span class=&quot;hljs-keyword&quot;&gt;insert&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;into&lt;/span&gt; #temp
        &lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@individual&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SET&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@products&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;SUBSTRING&lt;/span&gt;(&lt;span class=&quot;hljs-variable&quot;&gt;@products&lt;/span&gt;,
                                  LEN(&lt;span class=&quot;hljs-variable&quot;&gt;@individual&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;.&#39;&lt;/span&gt;) &lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;,
                                  LEN(&lt;span class=&quot;hljs-variable&quot;&gt;@products&lt;/span&gt;))
    &lt;span class=&quot;hljs-keyword&quot;&gt;END&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;ELSE&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;BEGIN&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SET&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@individual&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@products&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SET&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@products&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;insert&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;into&lt;/span&gt; #temp
        &lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@individual&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;END&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;END&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; #temp
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_13&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Ref: &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://stackoverflow.com/questions/2647/how-do-i-split-a-string-so-i-can-access-item-x&quot;&gt;How do I split a string so I can access item x?&lt;/a&gt;&lt;/p&gt;&lt;/div&gt; 

</content><link rel='replies' type='application/atom+xml' href='https://supers-affiliate.blogspot.com/feeds/8398491962910577512/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/how-to-convert-some-records-ins-sql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/8398491962910577512'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/8398491962910577512'/><link rel='alternate' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/how-to-convert-some-records-ins-sql.html' title='How To Convert Some Records Ins Sql Server'/><author><name>Blake Hickle</name><uri>http://www.blogger.com/profile/04290019036198769750</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7204472375574233207.post-5786209521881931316</id><published>2024-08-21T16:48:00.001-07:00</published><updated>2024-08-21T16:48:27.643-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><category scheme="http://www.blogger.com/atom/ns#" term="Sqlalchemy"/><title type='text'>Creating Self-referential Tables With Polymorphism In Sqlalchemy</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I&#39;m trying to create a db structure in which I have many types of content entities, of which one, a Comment, can be attached to any other. Consider the following: from datetime imp&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Try to supplement your &lt;code&gt;Comment.__mapper_args__&lt;/code&gt; to:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_1&quot; class=&quot;hljs language-python&quot;&gt;__mapper_args__ = {
    &lt;span class=&quot;hljs-string&quot;&gt;&#39;polymorphic_identity&#39;&lt;/span&gt;: &lt;span class=&quot;hljs-string&quot;&gt;&#39;comment&#39;&lt;/span&gt;,
    &lt;span class=&quot;hljs-string&quot;&gt;&#39;inherit_condition&#39;&lt;/span&gt;: (&lt;span class=&quot;hljs-built_in&quot;&gt;id&lt;/span&gt; == Entity.&lt;span class=&quot;hljs-built_in&quot;&gt;id&lt;/span&gt;),
}
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_1&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;P.S. I haven&#39;t understand what you need &lt;code&gt;_idref&lt;/code&gt; relationship for? If you want to use a comment somewhere where &lt;code&gt;Entity&lt;/code&gt; is expected you could just pass the &lt;code&gt;Comment&lt;/code&gt; instance as is.&lt;/p&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;To supplement @nailxx&#39;s answer:
Repeating all that boilerplate is tedious if you have many dependent tables.
Answer : move it all to a metaclass.&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;pre&gt;&lt;code id=&quot;code_5&quot; class=&quot;hljs language-python&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;hljs-title class_&quot;&gt;EntityMeta&lt;/span&gt;(&lt;span class=&quot;hljs-built_in&quot;&gt;type&lt;/span&gt;(Entity)):
    &lt;span class=&quot;hljs-keyword&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;hljs-title function_&quot;&gt;__init__&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot;&gt;cls, name, bases, dct&lt;/span&gt;):
        ident = dct.get(&lt;span class=&quot;hljs-string&quot;&gt;&#39;_identity&#39;&lt;/span&gt;,&lt;span class=&quot;hljs-literal&quot;&gt;None&lt;/span&gt;)
        &lt;span class=&quot;hljs-keyword&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;__abstract__&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;not&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;in&lt;/span&gt; dct:
            xid = Column(&lt;span class=&quot;hljs-literal&quot;&gt;None&lt;/span&gt;, ForeignKey(Entity.&lt;span class=&quot;hljs-built_in&quot;&gt;id&lt;/span&gt;), primary_key=&lt;span class=&quot;hljs-literal&quot;&gt;True&lt;/span&gt;)
            &lt;span class=&quot;hljs-built_in&quot;&gt;setattr&lt;/span&gt;(cls,&lt;span class=&quot;hljs-string&quot;&gt;&#39;id&#39;&lt;/span&gt;,xid)
            &lt;span class=&quot;hljs-built_in&quot;&gt;setattr&lt;/span&gt;(cls,&lt;span class=&quot;hljs-string&quot;&gt;&#39;__mapper_args__&#39;&lt;/span&gt;, { &lt;span class=&quot;hljs-string&quot;&gt;&#39;polymorphic_identity&#39;&lt;/span&gt;: dct[&lt;span class=&quot;hljs-string&quot;&gt;&#39;_identity&#39;&lt;/span&gt;], &lt;span class=&quot;hljs-string&quot;&gt;&#39;inherit_condition&#39;&lt;/span&gt;: (xid == Entity.&lt;span class=&quot;hljs-built_in&quot;&gt;id&lt;/span&gt;,), &lt;span class=&quot;hljs-string&quot;&gt;&#39;primary_key&#39;&lt;/span&gt;:(xid,) })
            &lt;span class=&quot;hljs-built_in&quot;&gt;setattr&lt;/span&gt;(cls,&lt;span class=&quot;hljs-string&quot;&gt;&#39;__tablename__&#39;&lt;/span&gt;,name.lower())
        &lt;span class=&quot;hljs-built_in&quot;&gt;super&lt;/span&gt;(EntityMeta, cls).__init__(name, bases, dct)

&lt;span class=&quot;hljs-keyword&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;hljs-title class_&quot;&gt;EntityRef&lt;/span&gt;(&lt;span class=&quot;hljs-title class_ inherited__&quot;&gt;Entity&lt;/span&gt;):
    __abstract__ = &lt;span class=&quot;hljs-literal&quot;&gt;True&lt;/span&gt;
    __metaclass__ = EntityMeta

&lt;span class=&quot;hljs-keyword&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;hljs-title class_&quot;&gt;Comment&lt;/span&gt;(&lt;span class=&quot;hljs-title class_ inherited__&quot;&gt;EntityRef&lt;/span&gt;):
    _identity = &lt;span class=&quot;hljs-string&quot;&gt;&#39;comment&#39;&lt;/span&gt;
    [...]
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_5&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Variations, as an exercise for the reader: You can omit the &lt;code&gt;_identity=…&lt;/code&gt; statement and use the class name, as in the &lt;code&gt;setattr(cls,&#39;__tablename__&#39;,…)&lt;/code&gt; line. Or not overwrite an existing __tablename__ or __mapper_args__ attribute.&lt;/p&gt;&lt;p&gt;Be sure to test &lt;code&gt;dct&lt;/code&gt; and not &lt;code&gt;cls&lt;/code&gt; for existence: the latter will find attributes in the parent class, which you obviously do not want at this point.&lt;/p&gt;&lt;/div&gt; 


</content><link rel='replies' type='application/atom+xml' href='https://supers-affiliate.blogspot.com/feeds/5786209521881931316/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/creating-self-referential-tables-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/5786209521881931316'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/5786209521881931316'/><link rel='alternate' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/creating-self-referential-tables-with.html' title='Creating Self-referential Tables With Polymorphism In Sqlalchemy'/><author><name>Blake Hickle</name><uri>http://www.blogger.com/profile/04290019036198769750</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7204472375574233207.post-3667491938546343708</id><published>2024-08-21T15:19:00.001-07:00</published><updated>2024-08-21T15:19:27.800-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C"/><category scheme="http://www.blogger.com/atom/ns#" term="Cocoa Touch"/><category scheme="http://www.blogger.com/atom/ns#" term="Sqlite"/><title type='text'>Sqlite3_open: &quot;unable To Open Database File&quot;</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I get &#39;unable to open database file&#39; when executing rc = sqlite3_open(&#39;test.db&#39;, &amp;db);  ?? sqlite3 *db; // sqlite3 db struct char *zErrMsg = 0; int rc;  // Open the test.db fil&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;&lt;code&gt;sqlite3_open&lt;/code&gt; returns an error if the database does not already exist. To create the database if it doesn&#39;t already exist, use &lt;code&gt;sqlite3_open_v2&lt;/code&gt; with the &lt;code&gt;SQLITE_OPEN_CREATE&lt;/code&gt; and &lt;code&gt;SQLITE_OPEN_READWRITE&lt;/code&gt; flags (&lt;strong&gt;both are required&lt;/strong&gt;):&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_4&quot; class=&quot;hljs language-ini&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;rc&lt;/span&gt; = sqlite3_open_v2(/* DB Path */, &amp;amp;db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL)&lt;span class=&quot;hljs-comment&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_4&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;&lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://www.sqlite.org/c3ref/open.html&quot;&gt;Reference&lt;/a&gt;&lt;/p&gt;&lt;hr&gt;&lt;p&gt;To find &lt;code&gt;/* DB PATH */&lt;/code&gt;, you need to base the filename off of the documents directory:&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;pre&gt;&lt;code id=&quot;code_6&quot; class=&quot;hljs language-objectivec&quot;&gt;- (&lt;span class=&quot;hljs-built_in&quot;&gt;NSString&lt;/span&gt; *) applicationDocumentsDirectory 
{    
    &lt;span class=&quot;hljs-built_in&quot;&gt;NSArray&lt;/span&gt; *paths = &lt;span class=&quot;hljs-built_in&quot;&gt;NSSearchPathForDirectoriesInDomains&lt;/span&gt;(&lt;span class=&quot;hljs-built_in&quot;&gt;NSDocumentDirectory&lt;/span&gt;, &lt;span class=&quot;hljs-built_in&quot;&gt;NSUserDomainMask&lt;/span&gt;, &lt;span class=&quot;hljs-literal&quot;&gt;YES&lt;/span&gt;);
    &lt;span class=&quot;hljs-built_in&quot;&gt;NSString&lt;/span&gt; *basePath = ([paths count] &amp;gt; &lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;) ? [paths objectAtIndex:&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;] : &lt;span class=&quot;hljs-literal&quot;&gt;nil&lt;/span&gt;;
    &lt;span class=&quot;hljs-keyword&quot;&gt;return&lt;/span&gt; basePath;
}
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_6&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;You can use this convenience method to combine the documents path with the database name:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_7&quot; class=&quot;hljs language-objectivec&quot;&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;NSString&lt;/span&gt; *documents = [&lt;span class=&quot;hljs-keyword&quot;&gt;self&lt;/span&gt; applicationDocumentsDirectory];
&lt;span class=&quot;hljs-built_in&quot;&gt;NSString&lt;/span&gt; *dbPath = [documents stringByAppendingPathComponent:&lt;span class=&quot;hljs-string&quot;&gt;@&quot;test.db&quot;&lt;/span&gt;];

rc = sqlite3_open_v2([dbPath UTF8String], &amp;amp;db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, &lt;span class=&quot;hljs-literal&quot;&gt;NULL&lt;/span&gt;);
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_7&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;pre&gt;&lt;code id=&quot;code_8&quot; class=&quot;hljs language-cpp&quot;&gt;&lt;span class=&quot;hljs-meta&quot;&gt;#&lt;span class=&quot;hljs-keyword&quot;&gt;define&lt;/span&gt; SQLITE_OK 0&lt;/span&gt;
sqlite3 *db;
&lt;span class=&quot;hljs-type&quot;&gt;char&lt;/span&gt; *zErrMsg=&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;;
&lt;span class=&quot;hljs-keyword&quot;&gt;if&lt;/span&gt;(&lt;span class=&quot;hljs-built_in&quot;&gt;sqlite3_open&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot;&gt;&quot;demo.db&quot;&lt;/span&gt;, &amp;amp;db) == SQLITE_OK)
{
    &lt;span class=&quot;hljs-keyword&quot;&gt;if&lt;/span&gt;(&lt;span class=&quot;hljs-built_in&quot;&gt;sqlite3_exec&lt;/span&gt;(db, &lt;span class=&quot;hljs-string&quot;&gt;&quot;select * from Users&quot;&lt;/span&gt;, callback, &lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;, &amp;amp;zErrMsg) == SQLITE_OK)
            &lt;span class=&quot;hljs-built_in&quot;&gt;msgbox1&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot;&gt;&quot;success&quot;&lt;/span&gt;);
    &lt;span class=&quot;hljs-built_in&quot;&gt;sqlite3_close&lt;/span&gt;(db);
}
&lt;span class=&quot;hljs-keyword&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;msgbox1&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot;&gt;&quot;failure&quot;&lt;/span&gt;);
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_8&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;here is the sample code which i use;&lt;/p&gt;&lt;/div&gt; 


</content><link rel='replies' type='application/atom+xml' href='https://supers-affiliate.blogspot.com/feeds/3667491938546343708/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/sqlite3open-unable-to-open-database-file.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/3667491938546343708'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/3667491938546343708'/><link rel='alternate' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/sqlite3open-unable-to-open-database-file.html' title='Sqlite3_open: &quot;unable To Open Database File&quot;'/><author><name>Blake Hickle</name><uri>http://www.blogger.com/profile/04290019036198769750</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7204472375574233207.post-6056986190443976839</id><published>2024-08-21T14:30:00.001-07:00</published><updated>2024-08-21T14:30:57.386-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="Entity Framework"/><category scheme="http://www.blogger.com/atom/ns#" term="Linq"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><title type='text'>Join A Table Using On Multiple Columns Using A Or Syntax</title><content type='html'>&lt;div class=&quot;question&quot;&gt;So what I&#39;m trying to do is :-  SELECT * FROM TableA JOIN TableB ON TableA.OriginPhoneNumber=TableB.Id OR TableA.DestinationPhoneNumber=TableB.Id  Rather strange query I know! But&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Just do a cross join with a where clause&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-csharp&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;var&lt;/span&gt; results = &lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; a &lt;span class=&quot;hljs-keyword&quot;&gt;in&lt;/span&gt; db.TableA
              &lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; b &lt;span class=&quot;hljs-keyword&quot;&gt;in&lt;/span&gt; db.TableB
              &lt;span class=&quot;hljs-keyword&quot;&gt;where&lt;/span&gt; a.OriginPhonenumber == b.Id 
                    || a.DestinationPhoneNumber == b.Id
              &lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;new&lt;/span&gt; { A = a, B = b };
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;It&#39;s doubtful that an or in a join condition would be more efficient than this, but it&#39;s likely that either would result in the same execution plan. Performance aside it will give the same results.&lt;/p&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;I used &lt;code&gt;Union&lt;/code&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;pre&gt;&lt;code id=&quot;code_2&quot; class=&quot;hljs language-csharp&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;var&lt;/span&gt; firstJoin=&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; tbl &lt;span class=&quot;hljs-keyword&quot;&gt;in&lt;/span&gt; TableA
    &lt;span class=&quot;hljs-keyword&quot;&gt;join&lt;/span&gt; c &lt;span class=&quot;hljs-keyword&quot;&gt;in&lt;/span&gt; TableB
        &lt;span class=&quot;hljs-keyword&quot;&gt;on&lt;/span&gt; c.OriginPhoneNumber Equals tbl.Id

&lt;span class=&quot;hljs-keyword&quot;&gt;var&lt;/span&gt; secondJoin=&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; tbl &lt;span class=&quot;hljs-keyword&quot;&gt;in&lt;/span&gt; TableA
    &lt;span class=&quot;hljs-keyword&quot;&gt;join&lt;/span&gt; c &lt;span class=&quot;hljs-keyword&quot;&gt;in&lt;/span&gt; TableB
        &lt;span class=&quot;hljs-keyword&quot;&gt;on&lt;/span&gt; c.DestinationPhoneNumber Equals tbl.Id

&lt;span class=&quot;hljs-keyword&quot;&gt;var&lt;/span&gt; result=firstJoin.Union(secondJoin)
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_2&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt; 


</content><link rel='replies' type='application/atom+xml' href='https://supers-affiliate.blogspot.com/feeds/6056986190443976839/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/join-table-using-on-multiple-columns.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/6056986190443976839'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/6056986190443976839'/><link rel='alternate' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/join-table-using-on-multiple-columns.html' title='Join A Table Using On Multiple Columns Using A Or Syntax'/><author><name>Blake Hickle</name><uri>http://www.blogger.com/profile/04290019036198769750</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7204472375574233207.post-3451660589502256842</id><published>2024-08-21T14:11:00.001-07:00</published><updated>2024-08-21T14:11:36.635-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Android"/><category scheme="http://www.blogger.com/atom/ns#" term="Cursor"/><category scheme="http://www.blogger.com/atom/ns#" term="Database"/><category scheme="http://www.blogger.com/atom/ns#" term="Sqlite"/><title type='text'>Activity Not Properly Managing Cursor.</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I have an activity that populates a list and does some other things from a cursor. I get the cursor from a method that returns it based on a standard android SQLite query to my dat&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Try closing the cursor in the &lt;code&gt;onPause()&lt;/code&gt; (&lt;code&gt;cursor.close()&lt;/code&gt;). If you are using a &lt;code&gt;SimpleCursorAdapter&lt;/code&gt; you should also detach the cursor from the adapter.&lt;/p&gt;&lt;p&gt;You can requery for the cursor in the &lt;code&gt;onResume()&lt;/code&gt; method if you wish.&lt;/p&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Well, it turns out that Cursor.requery() is depreciated and I was getting the same error every time I tried to call it. startManagingCursor() was calling requery, as I suppose it should, and that in turn was causing my problems there... I&#39;m not sure why requery is causing an error in this instance, I&#39;ve used it successfully before.&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;I ended up rearranging some code, and putting my cursor = SQLHelper.getwhatevercursor() code into onResume() instead of onCreate, as onResume is called right after onCreate anyway. As recommended by Nikola I am also closing the cursors in onPause().&lt;/p&gt;&lt;p&gt;This seems to be working now...&lt;/p&gt;&lt;/div&gt; 


</content><link rel='replies' type='application/atom+xml' href='https://supers-affiliate.blogspot.com/feeds/3451660589502256842/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/activity-not-properly-managing-cursor.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/3451660589502256842'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/3451660589502256842'/><link rel='alternate' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/activity-not-properly-managing-cursor.html' title='Activity Not Properly Managing Cursor.'/><author><name>Blake Hickle</name><uri>http://www.blogger.com/profile/04290019036198769750</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7204472375574233207.post-2872066112103175147</id><published>2024-08-21T13:55:00.001-07:00</published><updated>2024-08-21T13:55:00.564-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Postgresql"/><category scheme="http://www.blogger.com/atom/ns#" term="Postgresql 10"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><title type='text'>Interpreting Results From Explain Analyze In Postgres</title><content type='html'>&lt;div class=&quot;question&quot;&gt;Recently did a query which took about 9 minutes to complete. Attempting to determine why, I used EXPLAIN ANALYZE to help solve the problem. From the output, it looks as though ever&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Looking at your query exec plan a lot of time is spent on sorting&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-bash&quot;&gt;&lt;span class=&quot;hljs-string&quot;&gt;&quot;Sort  (cost=18.01..18.01 rows=1 width=86) (actual time=541075.198..541099.504 rows=65354 loops=1)&quot;&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&quot;  Sort Key: r.resource_id, s.start_date&quot;&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&quot;  Sort Method: external merge  Disk: 8016kB&quot;&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;I would recommend you to increase &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://www.postgresql.org/docs/current/runtime-config-resource.html#GUC-WORK-MEM&quot;&gt;work_mem&lt;/a&gt; param for &lt;code&gt;PostgreSQL&lt;/code&gt; as described &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server&quot;&gt;here &lt;/a&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;If you do a lot of complex sorts, and have a lot of memory, then increasing the work_mem parameter allows PostgreSQL to do larger
in-memory sorts which, unsurprisingly, will be faster than disk-based
equivalents.&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;This size is applied to each and every sort done by each user, and
complex queries can use multiple working memory sort buffers. Set it
to 50MB, and have 30 users submitting queries, and you are soon using
1.5GB of real memory. Furthermore, if a query involves doing merge sorts of 8 tables, that requires 8 times work_mem. You need to
consider what you set max_connections to in order to size this
parameter correctly. This is a setting where data warehouse systems,
where users are submitting very large queries, can readily make use of
many gigabytes of memory.&lt;/p&gt;&lt;p&gt;log_temp_files can be used to log sorts, hashes, and temp files which
can be useful in figuring out if sorts are spilling to disk instead of
fitting in memory. You can see sorts spilling to disk using EXPLAIN
ANALYZE plans as well. For example, if you see a line like Sort
Method: external merge Disk: 7526kB in the output of EXPLAIN ANALYZE,
a work_mem of at least 8MB would keep the intermediate data in memory
and likely improve the query response time (although it may take
substantially more than 8MB to do the sort entirely in memory, as data
on disk is stored in a more compact format).&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt; 

</content><link rel='replies' type='application/atom+xml' href='https://supers-affiliate.blogspot.com/feeds/2872066112103175147/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/interpreting-results-from-explain.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/2872066112103175147'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/2872066112103175147'/><link rel='alternate' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/interpreting-results-from-explain.html' title='Interpreting Results From Explain Analyze In Postgres'/><author><name>Blake Hickle</name><uri>http://www.blogger.com/profile/04290019036198769750</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7204472375574233207.post-8885919655239700035</id><published>2024-08-21T13:17:00.001-07:00</published><updated>2024-08-21T13:17:06.687-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Calendar"/><category scheme="http://www.blogger.com/atom/ns#" term="Date Range"/><category scheme="http://www.blogger.com/atom/ns#" term="Hive"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><title type='text'>How Can I Generate A Date Table With Fields Equals To &quot;dayofweek&quot;, &quot;weekofyear&quot; Etc ;and Rows Equals To Date From 2010-01-01 Till Current_date</title><content type='html'>&lt;div class=&quot;question&quot;&gt;How can i generate a Date table with fields like &#39;Dayofweek&#39;, &#39;weekofyear&#39; etc ;and rows equals to date from 2010-01-01 till current_date like below:              Dayofweek   Dayof&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Solution for Hive:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-csharp&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;set&lt;/span&gt; hivevar:start_date=&lt;span class=&quot;hljs-number&quot;&gt;2010&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-01&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;-01&lt;/span&gt;; --replace &lt;span class=&quot;hljs-keyword&quot;&gt;with&lt;/span&gt; your start_date
&lt;span class=&quot;hljs-keyword&quot;&gt;set&lt;/span&gt; hivevar:end_date=current_date; --&lt;span class=&quot;hljs-function&quot;&gt;replace &lt;span class=&quot;hljs-keyword&quot;&gt;with&lt;/span&gt; your end_date

&lt;span class=&quot;hljs-keyword&quot;&gt;with&lt;/span&gt; date_range &lt;span class=&quot;hljs-title&quot;&gt;as&lt;/span&gt; 
(&lt;span class=&quot;hljs-params&quot;&gt;--&lt;span class=&quot;hljs-keyword&quot;&gt;this&lt;/span&gt; query generates date range
&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt; date_add (&lt;span class=&quot;hljs-string&quot;&gt;&#39;${hivevar:start_date}&#39;&lt;/span&gt;,s.i&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt; dt 
  &lt;span class=&quot;hljs-title&quot;&gt;from&lt;/span&gt; (&lt;span class=&quot;hljs-params&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt; posexplode(split(space(datediff(${hivevar:end_date},&lt;span class=&quot;hljs-string&quot;&gt;&#39;${hivevar:start_date}&#39;&lt;/span&gt;&lt;/span&gt;)),&#39; &#39;)) &lt;span class=&quot;hljs-title&quot;&gt;as&lt;/span&gt; (&lt;span class=&quot;hljs-params&quot;&gt;i,x&lt;/span&gt;) ) s
),

holiday &lt;span class=&quot;hljs-title&quot;&gt;as&lt;/span&gt; (&lt;span class=&quot;hljs-params&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt; stack(&lt;span class=&quot;hljs-number&quot;&gt;5&lt;/span&gt;, --&lt;span class=&quot;hljs-keyword&quot;&gt;add&lt;/span&gt; more
             &lt;span class=&quot;hljs-string&quot;&gt;&#39;01-01&#39;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#39;New Year&#39;&lt;/span&gt;,
             &lt;span class=&quot;hljs-string&quot;&gt;&#39;01-21&#39;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#39;Martin Luther King Day&#39;&lt;/span&gt;,
             &lt;span class=&quot;hljs-string&quot;&gt;&#39;02-18&#39;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#39;Presidents Day&#39;&lt;/span&gt;,
             &lt;span class=&quot;hljs-string&quot;&gt;&#39;05-27&#39;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#39;Memorial Day&#39;&lt;/span&gt;,
             &lt;span class=&quot;hljs-string&quot;&gt;&#39;07-04&#39;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#39;Independence Day&#39;&lt;/span&gt;&lt;/span&gt;) &lt;span class=&quot;hljs-title&quot;&gt;as&lt;/span&gt; (&lt;span class=&quot;hljs-params&quot;&gt; mtdt,holiday_name&lt;/span&gt;)
) 

&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt; d.dt                                 &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt; date,
       &lt;span class=&quot;hljs-title&quot;&gt;date_format&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot;&gt;current_date,&lt;span class=&quot;hljs-string&quot;&gt;&#39;u&#39;&lt;/span&gt;&lt;/span&gt;)        &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt; dayofweek,
       &lt;span class=&quot;hljs-title&quot;&gt;day&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot;&gt;dt&lt;/span&gt;)                              &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt; dayofmonth,
       &lt;span class=&quot;hljs-title&quot;&gt;date_format&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot;&gt;current_date,&lt;span class=&quot;hljs-string&quot;&gt;&#39;D&#39;&lt;/span&gt;&lt;/span&gt;)        &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt; dayofyear,
       &lt;span class=&quot;hljs-title&quot;&gt;date_format&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot;&gt;current_date,&lt;span class=&quot;hljs-string&quot;&gt;&#39;W&#39;&lt;/span&gt;&lt;/span&gt;)        &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt; weekofmonth,
       &lt;span class=&quot;hljs-title&quot;&gt;weekofyear&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot;&gt;dt&lt;/span&gt;)                       &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt; weekofyear, 
       &lt;span class=&quot;hljs-keyword&quot;&gt;case&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;when&lt;/span&gt; h.mtdt &lt;span class=&quot;hljs-keyword&quot;&gt;is&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;not&lt;/span&gt;&lt;span class=&quot;hljs-literal&quot;&gt;null&lt;/span&gt; then &#39;Y&#39; &lt;span class=&quot;hljs-keyword&quot;&gt;else&lt;/span&gt; &#39;N&#39; end &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt; Holiday,
       h.holiday_name
  &lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; date_range d 
       left &lt;span class=&quot;hljs-keyword&quot;&gt;join&lt;/span&gt; holiday h &lt;span class=&quot;hljs-keyword&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;hljs-title&quot;&gt;substr&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot;&gt;d.dt,&lt;span class=&quot;hljs-number&quot;&gt;6&lt;/span&gt;&lt;/span&gt;)&lt;/span&gt;= h.mtdt
;
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Add more holidays. &lt;/p&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;You can get a calendar table with the following solution:&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;pre&gt;&lt;code id=&quot;code_1&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; calendar.&lt;span class=&quot;hljs-operator&quot;&gt;*&lt;/span&gt;, 
    DATEPART(dw, calendar.date_value) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; DayOfWeek, 
    DATEPART(dd, calendar.date_value) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; DayOfMonth, 
    DATEPART(dy, calendar.date_value) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; DayOfYear,
    DATEPART(wk, calendar.date_value) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; WeekOfYear, 
    &lt;span class=&quot;hljs-keyword&quot;&gt;CASE&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;WHEN&lt;/span&gt; holidays.date_value &lt;span class=&quot;hljs-keyword&quot;&gt;IS&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;THEN&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;N&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;ELSE&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;J&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;END&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; Holiday 
&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; (
  &lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; DATEADD(&lt;span class=&quot;hljs-keyword&quot;&gt;DAY&lt;/span&gt;, t4 &lt;span class=&quot;hljs-operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;10000&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt; t3 &lt;span class=&quot;hljs-operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt; t2 &lt;span class=&quot;hljs-operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt; t1 &lt;span class=&quot;hljs-operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt; t0, &lt;span class=&quot;hljs-string&quot;&gt;&#39;1970-01-01&#39;&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; date_value &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt;
    (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt; t0 &lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;9&lt;/span&gt;) t0,
    (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt; t1 &lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;9&lt;/span&gt;) t1,
    (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt; t2 &lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;9&lt;/span&gt;) t2,
    (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt; t3 &lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;9&lt;/span&gt;) t3,
    (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt; t4 &lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;9&lt;/span&gt;) t4
) calendar &lt;span class=&quot;hljs-keyword&quot;&gt;INNER&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;JOIN&lt;/span&gt; (
  &lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;2010-01-01&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; date_value &lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;2010-01-06&#39;&lt;/span&gt;
) holidays &lt;span class=&quot;hljs-keyword&quot;&gt;ON&lt;/span&gt; calendar.date_value &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; holidays.date_value
&lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt; calendar.date_value &lt;span class=&quot;hljs-keyword&quot;&gt;BETWEEN&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;CAST&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot;&gt;&#39;2010-01-01&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;DATE&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot;&gt;AND&lt;/span&gt; GETDATE()
&lt;span class=&quot;hljs-keyword&quot;&gt;ORDER&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;BY&lt;/span&gt; calendar.date_value
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_1&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;The basic calendar table is based on &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://stackoverflow.com/a/45992247/3840840&quot;&gt;this solution on StackOverflow&lt;/a&gt;. With the &lt;code&gt;INNER JOIN&lt;/code&gt; you can add some holidays.&lt;/p&gt;&lt;p&gt;With &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://docs.microsoft.com/en-us/sql/t-sql/functions/datepart-transact-sql&quot;&gt;&lt;code&gt;DATEPART&lt;/code&gt;&lt;/a&gt; you can get some information about the date.&lt;/p&gt;&lt;/div&gt; 


</content><link rel='replies' type='application/atom+xml' href='https://supers-affiliate.blogspot.com/feeds/8885919655239700035/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/how-can-i-generate-date-table-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/8885919655239700035'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/8885919655239700035'/><link rel='alternate' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/how-can-i-generate-date-table-with.html' title='How Can I Generate A Date Table With Fields Equals To &quot;dayofweek&quot;, &quot;weekofyear&quot; Etc ;and Rows Equals To Date From 2010-01-01 Till Current_date'/><author><name>Blake Hickle</name><uri>http://www.blogger.com/profile/04290019036198769750</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7204472375574233207.post-6832094307811987841</id><published>2024-08-21T12:57:00.001-07:00</published><updated>2024-08-21T12:57:52.391-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ado"/><category scheme="http://www.blogger.com/atom/ns#" term="Delphi"/><category scheme="http://www.blogger.com/atom/ns#" term="Delphi 5"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><title type='text'>&quot;object Was Open&quot; Error Using Delphi, Sql Server And Ado</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I am getting an &#39;Object Was Open&#39; error when opening a TADOQuery which returns a large dataset (around 700,000 rows and 75 columns). 8 of my fields are derived fields as varchar(20&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;I was receiving the same error and, for me, some changes to my TAdoQuery properties fixed it. My situation is somewhat different than yours, so I&#39;ll describe it before getting to the changes that worked for me.&lt;/p&gt;&lt;p&gt;I have a fairly large table; 684,673 rows, 107 columns and a data size of 636240 KB. It has three sets of repeating columns that I&#39;m going to normalize out to three new tables. The query?&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; MyTable
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;So this is just a straight run through the table, one direction only. The processing has no need for any particular order, so adding indexes, beyond the primary key, won&#39;t help. Since I&#39;m making no changes to this table, it&#39;s a read-only proposition. Nothing needs to be displayed.&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;I was receiving the error in the Delphi IDE when I simply tried to set this table&#39;s TADOQuery.Active property to true. In other words, just trying to open it in the IDE threw the error. There&#39;s no point in examining any of my code before I can successfully open this in the IDE.&lt;/p&gt;&lt;p&gt;I made the following changes to this table&#39;s TADOQuery:&lt;/p&gt;&lt;p&gt;CommandTimeout: &lt;strong&gt;600&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;CursorLocation: &lt;strong&gt;clUseServer&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;CursorType: &lt;strong&gt;ctOpenForwardOnly&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;EnableBCD: &lt;strong&gt;False&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;LockType: &lt;strong&gt;ltReadOnly&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;The error no longer happens, either in the IDE or in my processing code.&lt;/p&gt;&lt;p&gt;It may be that only one of these changes was necessary. If so, I don&#39;t know which because I didn&#39;t test them one-at-a-time. I simply made all the changes that looked like candidates to give the query the best chance of success.&lt;/p&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Just change the query of &lt;code&gt;YourADOQuery&lt;/code&gt; (if applied) before setting it&#39;s Active property to true as below:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_2&quot; class=&quot;hljs language-css&quot;&gt;YourADOQuery&lt;span class=&quot;hljs-selector-class&quot;&gt;.SQL&lt;/span&gt;&lt;span class=&quot;hljs-selector-class&quot;&gt;.Text&lt;/span&gt; := &lt;span class=&quot;hljs-string&quot;&gt;&#39;select top 100 * from &#39;&lt;/span&gt; + YourADOQuery.SQL.Text + &lt;span class=&quot;hljs-string&quot;&gt;&#39;)a&#39;&lt;/span&gt;;
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_2&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Note that &lt;code&gt;100&lt;/code&gt; is NOT &#39;100 PERCENT&#39;! but returns 100 percent of records :)&lt;/p&gt;&lt;/div&gt; 


</content><link rel='replies' type='application/atom+xml' href='https://supers-affiliate.blogspot.com/feeds/6832094307811987841/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/object-was-open-error-using-delphi-sql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/6832094307811987841'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/6832094307811987841'/><link rel='alternate' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/object-was-open-error-using-delphi-sql.html' title='&quot;object Was Open&quot; Error Using Delphi, Sql Server And Ado'/><author><name>Blake Hickle</name><uri>http://www.blogger.com/profile/04290019036198769750</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7204472375574233207.post-3778347072671014870</id><published>2024-08-21T12:38:00.001-07:00</published><updated>2024-08-21T12:38:32.587-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><category scheme="http://www.blogger.com/atom/ns#" term="Sqlxml"/><category scheme="http://www.blogger.com/atom/ns#" term="Xml"/><category scheme="http://www.blogger.com/atom/ns#" term="Xquery"/><title type='text'>How Can I Query A Sql Server Xml Column And Return All Values For A Specific Node?</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I have the following XML in a XML column in SQL Server.   &lt;qualifiers&gt;&lt;qualifier&gt;&lt;key&gt;111&lt;/key&gt;&lt;message&gt;a match was not found&lt;/m&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;&lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;http://sqlfiddle.com/#!3/f6df1/2&quot;&gt;SQLFiddle&lt;/a&gt; for the same: Solution as per @xQbert suggested&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-xml&quot;&gt;create table Temp (col1 xml)
go

insert into Temp (col1)
values(&#39;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;qualifiers&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;qualifier&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;key&lt;/span&gt;&amp;gt;&lt;/span&gt;111&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;key&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;message&lt;/span&gt;&amp;gt;&lt;/span&gt;a match was not found&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;message&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;qualifier&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;qualifier&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;key&lt;/span&gt;&amp;gt;&lt;/span&gt;222&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;key&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;message&lt;/span&gt;&amp;gt;&lt;/span&gt;a match was found&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;message&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;qualifier&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;qualifier&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;key&lt;/span&gt;&amp;gt;&lt;/span&gt;333&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;key&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;message&lt;/span&gt;&amp;gt;&lt;/span&gt;error&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;message&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;qualifier&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;qualifiers&lt;/span&gt;&amp;gt;&lt;/span&gt;&#39;)
go

SELECT
    STUFF((SELECT 
              &#39;,&#39; + fd.v.value(&#39;(.)[1]&#39;, &#39;varchar(50)&#39;)
           FROM 
              Temp
           CROSS APPLY
              col1.nodes(&#39;/qualifiers/qualifier/message&#39;) AS fd(v)
           FOR XML PATH(&#39;&#39;)
          ), 1, 1, &#39;&#39;)
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;I believe that is what you are looking for :
-- it is from the LINK :
-- &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;http://blog.sqlauthority.com/2009/02/13/sql-server-simple-example-of-reading-xml-file-using-t-sql/&quot;&gt;http://blog.sqlauthority.com/2009/02/13/sql-server-simple-example-of-reading-xml-file-using-t-sql/&lt;/a&gt;&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_1&quot; class=&quot;hljs language-php&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;DECLARE&lt;/span&gt; @MyXML XML
SET @MyXML = &lt;span class=&quot;hljs-string&quot;&gt;&#39;&amp;lt;SampleXML&amp;gt;
&amp;lt;Colors&amp;gt;
&amp;lt;Color1&amp;gt;White&amp;lt;/Color1&amp;gt;
&amp;lt;Color2&amp;gt;Blue&amp;lt;/Color2&amp;gt;
&amp;lt;Color3&amp;gt;Black&amp;lt;/Color3&amp;gt;
&amp;lt;Color4 Special=&quot;Light&quot;&amp;gt;Green&amp;lt;/Color4&amp;gt;
&amp;lt;Color5&amp;gt;Red&amp;lt;/Color5&amp;gt;
&amp;lt;/Colors&amp;gt;
&amp;lt;Fruits&amp;gt;
&amp;lt;Fruits1&amp;gt;Apple&amp;lt;/Fruits1&amp;gt;
&amp;lt;Fruits2&amp;gt;Pineapple&amp;lt;/Fruits2&amp;gt;
&amp;lt;Fruits3&amp;gt;Grapes&amp;lt;/Fruits3&amp;gt;
&amp;lt;Fruits4&amp;gt;Melon&amp;lt;/Fruits4&amp;gt;
&amp;lt;/Fruits&amp;gt;
&amp;lt;/SampleXML&amp;gt;&#39;&lt;/span&gt;

SELECT
a.b.value(&lt;span class=&quot;hljs-string&quot;&gt;&#39;Colors[1]/Color1[1]&#39;&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot;&gt;&#39;varchar(10)&#39;&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; Color1,
a.b.value(&lt;span class=&quot;hljs-string&quot;&gt;&#39;Colors[1]/Color2[1]&#39;&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot;&gt;&#39;varchar(10)&#39;&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; Color2,
a.b.value(&lt;span class=&quot;hljs-string&quot;&gt;&#39;Colors[1]/Color3[1]&#39;&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot;&gt;&#39;varchar(10)&#39;&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; Color3,
a.b.value(&lt;span class=&quot;hljs-string&quot;&gt;&#39;Colors[1]/Color4[1]/@Special&#39;&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot;&gt;&#39;varchar(10)&#39;&lt;/span&gt;)+&lt;span class=&quot;hljs-string&quot;&gt;&#39; &#39;&lt;/span&gt;+
+a.b.value(&lt;span class=&quot;hljs-string&quot;&gt;&#39;Colors[1]/Color4[1]&#39;&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot;&gt;&#39;varchar(10)&#39;&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; Color4,
a.b.value(&lt;span class=&quot;hljs-string&quot;&gt;&#39;Colors[1]/Color5[1]&#39;&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot;&gt;&#39;varchar(10)&#39;&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; Color5,
a.b.value(&lt;span class=&quot;hljs-string&quot;&gt;&#39;Fruits[1]/Fruits1[1]&#39;&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot;&gt;&#39;varchar(10)&#39;&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; Fruits1,
a.b.value(&lt;span class=&quot;hljs-string&quot;&gt;&#39;Fruits[1]/Fruits2[1]&#39;&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot;&gt;&#39;varchar(10)&#39;&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; Fruits2,
a.b.value(&lt;span class=&quot;hljs-string&quot;&gt;&#39;Fruits[1]/Fruits3[1]&#39;&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot;&gt;&#39;varchar(10)&#39;&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; Fruits3,
a.b.value(&lt;span class=&quot;hljs-string&quot;&gt;&#39;Fruits[1]/Fruits4[1]&#39;&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot;&gt;&#39;varchar(10)&#39;&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; Fruits4
&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; @MyXML.nodes(&lt;span class=&quot;hljs-string&quot;&gt;&#39;SampleXML&#39;&lt;/span&gt;) a(b)
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_1&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='https://supers-affiliate.blogspot.com/feeds/3778347072671014870/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/how-can-i-query-sql-server-xml-column.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/3778347072671014870'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/3778347072671014870'/><link rel='alternate' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/how-can-i-query-sql-server-xml-column.html' title='How Can I Query A Sql Server Xml Column And Return All Values For A Specific Node?'/><author><name>Blake Hickle</name><uri>http://www.blogger.com/profile/04290019036198769750</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7204472375574233207.post-859180204748321760</id><published>2024-08-21T12:18:00.001-07:00</published><updated>2024-08-21T12:18:43.534-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><category scheme="http://www.blogger.com/atom/ns#" term="Sqlxml"/><category scheme="http://www.blogger.com/atom/ns#" term="Tsql"/><title type='text'>Sql Xml Path With Different Children</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I have done a lot of XML PATH statements, but this one escapes me or might not even be possible with multiple different children. The end result should look like this  &lt;Process&amp;&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot; style=&quot;height: auto !important;&quot;&gt;&lt;p&gt;Right, you have a multitude of issues to overcome with your sample!&lt;/p&gt;&lt;p&gt;Firstly, I&#39;ll give you the answer, although note that in order to process hierarchically correctly it had to be a recursive function, so the test data you provided had to be created in permanent tables rather than temporary (simpler)
and then I&#39;ll point out a few useful techniques that I used in it to solve the problem.&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;ALTER&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;FUNCTION&lt;/span&gt; GetTasks (&lt;span class=&quot;hljs-variable&quot;&gt;@ParentId&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;varchar&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot;&gt;255&lt;/span&gt;)&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;NULL&lt;/span&gt;) 
&lt;span class=&quot;hljs-keyword&quot;&gt;RETURNS&lt;/span&gt;
XML
&lt;span class=&quot;hljs-keyword&quot;&gt;BEGIN&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;DECLARE&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@ReturnXML&lt;/span&gt; XML

&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@ReturnXML&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; 
(
    &lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;
    (
        &lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;CONVERT&lt;/span&gt;(XML,
                &lt;span class=&quot;hljs-comment&quot;&gt;--Main task start tag&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;&amp;lt;&#39;&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;master_t.TaskType&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39; Name=&quot;&#39;&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;master_t.TaskName&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;&quot;&amp;gt;&#39;&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;CONVERT&lt;/span&gt;(&lt;span class=&quot;hljs-type&quot;&gt;VARCHAR&lt;/span&gt;(MAX),
                        (

                            &lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;
                            dbo.GetTasks(master_t.TaskId),
                            (
                                &lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;CONVERT&lt;/span&gt;(XML,&lt;span class=&quot;hljs-string&quot;&gt;&#39;&amp;lt;&#39;&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;DetailName&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;&amp;gt;&#39;&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;DetailValue&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;&amp;lt;/&#39;&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;DetailName&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;&amp;gt;&#39;&lt;/span&gt;)
                                &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt;
                                    TASK_DETAILS t 
                                &lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt;
                                    TaskId &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; master_t.TaskId
                                &lt;span class=&quot;hljs-keyword&quot;&gt;FOR&lt;/span&gt; XML PATH(&lt;span class=&quot;hljs-string&quot;&gt;&#39;&#39;&lt;/span&gt;),Type
                            ),
                            (
                                &lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; Name,&lt;span class=&quot;hljs-keyword&quot;&gt;Value&lt;/span&gt;,Type &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; TASK_PARAMETERS t 
                                &lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt; TaskId&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;master_t.TaskId
                                &lt;span class=&quot;hljs-keyword&quot;&gt;FOR&lt;/span&gt; XML PATH(&lt;span class=&quot;hljs-string&quot;&gt;&#39;Parameter&#39;&lt;/span&gt;),Type
                            ) &lt;span class=&quot;hljs-string&quot;&gt;&#39;Parameters&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;FOR&lt;/span&gt; XML PATH(&lt;span class=&quot;hljs-string&quot;&gt;&#39;&#39;&lt;/span&gt;),Type 
                        )
                    )
                    &lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;--Main task end tag&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;&amp;lt;/&#39;&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;master_t.TaskType&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;&amp;gt;&#39;&lt;/span&gt;
            )
        &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; 
            TASK master_t
        &lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;--Effectively ignore the parentId field if it is not passed.&lt;/span&gt;
            ISNULL(ParentTaskId,&lt;span class=&quot;hljs-string&quot;&gt;&#39;&#39;&lt;/span&gt;) &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;CASE&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;WHEN&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@ParentId&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;IS&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;THEN&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;ELSE&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@ParentId&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;END&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;FOR&lt;/span&gt; XML PATH(&lt;span class=&quot;hljs-string&quot;&gt;&#39;&#39;&lt;/span&gt;),Type
    ) &lt;span class=&quot;hljs-string&quot;&gt;&#39;TaskList&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;FOR&lt;/span&gt; XML PATH(&lt;span class=&quot;hljs-string&quot;&gt;&#39;&#39;&lt;/span&gt;),Type
) 

&lt;span class=&quot;hljs-keyword&quot;&gt;RETURN&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@ReturnXML&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;END&lt;/span&gt;
GO
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Call this function like this:&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;pre&gt;&lt;code id=&quot;code_1&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; dbo.GetTasks(&lt;span class=&quot;hljs-keyword&quot;&gt;NULL&lt;/span&gt;)
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_1&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Right the techniques that I think are worth noting are:&lt;/p&gt;&lt;p&gt;a) You can manually create xml nodes by simply building them from strings- this is useful if the node names are in the table. The only thing you have to be aware of is that to put an open and closing tag around a block, you will probably have to convert the block to a string first, tack on the tags, and then convert the whole thing to xml (piecemeal wont work as the convert-to-xml function would expect you to provide well formed XML.&lt;/p&gt;&lt;p&gt;b) You sometimes have to nest things in brackets to achieve a tag around all the subtags...
An example makes this clearer:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_2&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; 
    TaskName
    &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; TASK t
    &lt;span class=&quot;hljs-keyword&quot;&gt;FOR&lt;/span&gt; XML PATH(&lt;span class=&quot;hljs-string&quot;&gt;&#39;SomeRoot&#39;&lt;/span&gt;)
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_2&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;would yield:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_3&quot; class=&quot;hljs language-xml&quot;&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;SomeRoot&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;TaskName&lt;/span&gt;&amp;gt;&lt;/span&gt;Get Report Parameters&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;TaskName&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;SomeRoot&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;SomeRoot&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;TaskName&lt;/span&gt;&amp;gt;&lt;/span&gt;Loop Report Creation&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;TaskName&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;SomeRoot&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;SomeRoot&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;TaskName&lt;/span&gt;&amp;gt;&lt;/span&gt;Report In Loop&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;TaskName&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;SomeRoot&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;SomeRoot&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;TaskName&lt;/span&gt;&amp;gt;&lt;/span&gt;Get Email Addresses&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;TaskName&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;SomeRoot&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;SomeRoot&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;TaskName&lt;/span&gt;&amp;gt;&lt;/span&gt;Loop Mail Creation&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;TaskName&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;SomeRoot&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;SomeRoot&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;TaskName&lt;/span&gt;&amp;gt;&lt;/span&gt;Send Email In Loop&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;TaskName&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;SomeRoot&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_3&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;To get the &quot;SomeRoot&quot; to appear around it, you could do this:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_4&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; 
(
    &lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; 
        TaskName
    &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; TASK t
    &lt;span class=&quot;hljs-keyword&quot;&gt;FOR&lt;/span&gt; XML PATH(&lt;span class=&quot;hljs-string&quot;&gt;&#39;&#39;&lt;/span&gt;),Type
) 
&lt;span class=&quot;hljs-keyword&quot;&gt;FOR&lt;/span&gt; XML PATH(&lt;span class=&quot;hljs-string&quot;&gt;&#39;SomeRoot&#39;&lt;/span&gt;)
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_4&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;If the node name is static (Note the XML PATH(&#39;&#39;)&lt;strong&gt;,Type&lt;/strong&gt;, which basically ensures that XML path returns XML type data for further processing and doesn&#39;t escape it)&lt;/p&gt;&lt;p&gt;If the node name is NOT static, you&#39;re stuck with something like this, with the need to convert to and from string to make it work. &lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_5&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;CONVERT&lt;/span&gt;(XML,
        &lt;span class=&quot;hljs-string&quot;&gt;&#39;&amp;lt;&#39;&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;DynamicName&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;&amp;gt;&#39;&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;CONVERT&lt;/span&gt;(&lt;span class=&quot;hljs-type&quot;&gt;VARCHAR&lt;/span&gt;(MAX),
                (
                    &lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; 
                        TaskName
                    &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; TASK t
                    &lt;span class=&quot;hljs-keyword&quot;&gt;FOR&lt;/span&gt; XML PATH(&lt;span class=&quot;hljs-string&quot;&gt;&#39;&#39;&lt;/span&gt;),Type
                )
            ) &lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;&amp;lt;/&#39;&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;DynamicName&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;&amp;gt;&#39;&lt;/span&gt;  
    )
&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt;
    (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;Test&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt; DynamicName) a
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_5&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;c) Regarding your question about getting different children tags to appear on the same level, it&#39;s pretty trivial, and you just have to remember that the usual problem of multiple layers of select ceases to be a problem with xml as an xml select just returns a single xml object. You can then use XML PATH to combine those results in a tree too.&lt;/p&gt;&lt;p&gt;e.g.&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_6&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; 
    (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; top &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; TASK &lt;span class=&quot;hljs-keyword&quot;&gt;FOR&lt;/span&gt; XML PATH(&lt;span class=&quot;hljs-string&quot;&gt;&#39;&#39;&lt;/span&gt;),Type),
    (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; top &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; TASK_DETAILS &lt;span class=&quot;hljs-keyword&quot;&gt;FOR&lt;/span&gt; XML PATH(&lt;span class=&quot;hljs-string&quot;&gt;&#39;&#39;&lt;/span&gt;),Type)
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_6&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Will return a single row with two columns but if you then apply XML PATH(&#39;&#39;) To the whole, you&#39;ve combined them on the same level&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_7&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; 
    (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; top &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; TASK &lt;span class=&quot;hljs-keyword&quot;&gt;FOR&lt;/span&gt; XML PATH(&lt;span class=&quot;hljs-string&quot;&gt;&#39;&#39;&lt;/span&gt;),Type),
    (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; top &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; TASK_DETAILS &lt;span class=&quot;hljs-keyword&quot;&gt;FOR&lt;/span&gt; XML PATH(&lt;span class=&quot;hljs-string&quot;&gt;&#39;&#39;&lt;/span&gt;),Type)
&lt;span class=&quot;hljs-keyword&quot;&gt;FOR&lt;/span&gt; XML PATH(&lt;span class=&quot;hljs-string&quot;&gt;&#39;Root&#39;&lt;/span&gt;)    
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_7&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;d) Column names are converted into nodes for you if by XML PATH. Attributes are quite easy in that you just give the column an alias which is the appropriate xsl path
e.g. &#39;MyNodeName\@MyAttributeName&#39; obviously this precludes attributes that are also dynamically named. For that, in this example, I just built the xml from strings again. This incidentally is why dynamic node names is such a bad idea-- you basically allow your routine to create new attribute names and node names via data in the table... this means that you can&#39;t create a decent schema for your routine as you don&#39;t know in advance what data might be in the table... &lt;/p&gt;&lt;p&gt;Moving on :)&lt;/p&gt;&lt;p&gt;So, given those building blocks, the easiest thing to do is work from the deepest level, and build it block by block, then combine like above.&lt;/p&gt;&lt;p&gt;I did that for your query, and eventually realised that to make it work hierarchically (i.e. n-nested levels) I had to write is as a function returning XML, which is called passing the parentnode to it (so that the function knows what to filter the result set down to). This will die a horrible death if you hierarchy is ill-formed and circular.&lt;/p&gt;&lt;p&gt;Okay- hopefully there&#39;s something in there you can work with. This is purely XML PATH() oriented solution - there are alternative XML methods which can be useful in different situations.&lt;/p&gt;&lt;/div&gt; 

</content><link rel='replies' type='application/atom+xml' href='https://supers-affiliate.blogspot.com/feeds/859180204748321760/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/sql-xml-path-with-different-children.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/859180204748321760'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/859180204748321760'/><link rel='alternate' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/sql-xml-path-with-different-children.html' title='Sql Xml Path With Different Children'/><author><name>Blake Hickle</name><uri>http://www.blogger.com/profile/04290019036198769750</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7204472375574233207.post-2696174213112470659</id><published>2024-08-21T11:59:00.001-07:00</published><updated>2024-08-21T11:59:20.688-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Greatest N Per Group"/><category scheme="http://www.blogger.com/atom/ns#" term="Inner Join"/><category scheme="http://www.blogger.com/atom/ns#" term="Mysql"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Order By"/><title type='text'>Greatest N-per-group With Multiple Joins</title><content type='html'>&lt;div class=&quot;question&quot;&gt;Evening, I am trying to get an output of rows that are limited to n per group in MySQL. I can get it to work without joins, but with it I am just shy. I&#39;ve pasted a dump of the rel&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;This works:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SET&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@num&lt;/span&gt; :&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;hljs-variable&quot;&gt;@prevCat&lt;/span&gt; :&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;;
&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; title, &lt;span class=&quot;hljs-keyword&quot;&gt;start&lt;/span&gt;, &lt;span class=&quot;hljs-keyword&quot;&gt;end&lt;/span&gt;, type, description, linkOut, outType, catRef, row_number
&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; (
&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; title, &lt;span class=&quot;hljs-keyword&quot;&gt;start&lt;/span&gt;, &lt;span class=&quot;hljs-keyword&quot;&gt;end&lt;/span&gt;, type, description, linkOut, outType, catRef,
&lt;span class=&quot;hljs-variable&quot;&gt;@num&lt;/span&gt; :&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; if(&lt;span class=&quot;hljs-variable&quot;&gt;@prevCat&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; catRef, &lt;span class=&quot;hljs-variable&quot;&gt;@num&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt; row_number,
&lt;span class=&quot;hljs-variable&quot;&gt;@prevCat&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; tog,
&lt;span class=&quot;hljs-variable&quot;&gt;@prevCat&lt;/span&gt; :&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; catRef &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; dummy
&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; (
    &lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; title, &lt;span class=&quot;hljs-keyword&quot;&gt;start&lt;/span&gt;, &lt;span class=&quot;hljs-keyword&quot;&gt;end&lt;/span&gt;, resources.type, description, linkOut, outType, catRef
    &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; resources &lt;span class=&quot;hljs-keyword&quot;&gt;LEFT&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;JOIN&lt;/span&gt; placesRel &lt;span class=&quot;hljs-keyword&quot;&gt;ON&lt;/span&gt; placesRel.refId &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; resId &lt;span class=&quot;hljs-keyword&quot;&gt;LEFT&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;JOIN&lt;/span&gt; catRel &lt;span class=&quot;hljs-keyword&quot;&gt;ON&lt;/span&gt; catRel.refId &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; resId
    &lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt; status &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;live&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;AND&lt;/span&gt; placesRel.type &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;res&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;AND&lt;/span&gt; catRel.type &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;res&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;ORDER&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;BY&lt;/span&gt; catRef
) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; w
) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; x &lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt; x.row_number &lt;span class=&quot;hljs-operator&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;4&lt;/span&gt;;
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;You need to put your joined query in a sub-query and order it by the column you want to group by. Use it&#39;s parent query to add row numbers. Then, the top-level query glues it all together.&lt;/p&gt;&lt;p&gt;If you don&#39;t put your joined query in it&#39;s own sub-query, the results won&#39;t be ordered as you wish, but instead will come out in the order they are in the database. This means the data is not grouped, so row numbers will no be applied to ordered rows.&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt; 

</content><link rel='replies' type='application/atom+xml' href='https://supers-affiliate.blogspot.com/feeds/2696174213112470659/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/greatest-n-per-group-with-multiple-joins.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/2696174213112470659'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/2696174213112470659'/><link rel='alternate' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/greatest-n-per-group-with-multiple-joins.html' title='Greatest N-per-group With Multiple Joins'/><author><name>Blake Hickle</name><uri>http://www.blogger.com/profile/04290019036198769750</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7204472375574233207.post-6929002506151110450</id><published>2024-08-21T11:39:00.001-07:00</published><updated>2024-08-21T11:39:25.850-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Mysql"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><title type='text'>How To Use Fuzzy Look Up To Find The Sentence In Sql?</title><content type='html'>&lt;div class=&quot;question&quot;&gt;search term=[&#39;ISBN number on site&#39;] the variable(column): sentence,  in MySQL table. It consist many different sentence.  the sentence I want to look for is  &#39;The AutoLink feature&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;This is not a simple question. Your best bet is to use some type of &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://dev.mysql.com/doc/refman/5.7/en/fulltext-search.html&quot;&gt;fulltext search&lt;/a&gt;. Fulltext search can be configured to have stopwords (words that are omitted from search - like the word &lt;code&gt;the&lt;/code&gt;) and can have a minimum word length limit as well (words with less than certain characters long are also omitted from the search.&lt;/p&gt;&lt;p&gt;However, if you simply use&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_1&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; testtable
&lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;MATCH&lt;/span&gt; (sentence)
AGAINST (&lt;span class=&quot;hljs-string&quot;&gt;&#39;ISBN number on site&#39;&lt;/span&gt;);
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_1&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Then MySQL will return not just the record with the value you were looking for, but the records that have some of the words only, and in different order. The one you showed will probably be one of the highest ranking one, but there is no guarantee that it will be highest ranked one.&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;You may want to use &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://dev.mysql.com/doc/refman/5.7/en/fulltext-boolean.html&quot;&gt;Boolean fulltext search&lt;/a&gt; and prepend &lt;code&gt;+&lt;/code&gt; to every search word to force MySQL to return those records only that have all the search words present:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_3&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; testtable
&lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;MATCH&lt;/span&gt; (sentence)
AGAINST (&lt;span class=&quot;hljs-string&quot;&gt;&#39;+ISBN +number +on +site&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;IN&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;BOOLEAN&lt;/span&gt; MODE);
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_3&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;But, &lt;code&gt;on&lt;/code&gt; should either be a stopword (it is on the default stipword lists) or should be shorter that the minimum word length, so should be omitted from the search expression (you will not get back any results):&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_5&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; testtable
&lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;MATCH&lt;/span&gt; (sentence)
AGAINST (&lt;span class=&quot;hljs-string&quot;&gt;&#39;+ISBN +number +site&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;IN&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;BOOLEAN&lt;/span&gt; MODE);
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_5&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;I know that this requires alteration of the search expression, however this will get you the best results using MySQL&#39;s built-in functionality.&lt;/p&gt;&lt;p&gt;The alternative is to use other fulltext search engines, such as &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;http://sphinxsearch.com/blog/2014/11/05/sphinx-search-quick-tour-using-a-mysql-datasource/&quot;&gt;sphinx&lt;/a&gt; to perform the search for you.&lt;/p&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Try: &lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_6&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; testtable &lt;span class=&quot;hljs-keyword&quot;&gt;where&lt;/span&gt; Sentence &lt;span class=&quot;hljs-keyword&quot;&gt;like&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;%ISBN number on%site%&#39;&lt;/span&gt; ;
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_6&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;The wildcard can go in the middle of a string too.&lt;/p&gt;&lt;/div&gt; 


</content><link rel='replies' type='application/atom+xml' href='https://supers-affiliate.blogspot.com/feeds/6929002506151110450/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/how-to-use-fuzzy-look-up-to-find.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/6929002506151110450'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/6929002506151110450'/><link rel='alternate' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/how-to-use-fuzzy-look-up-to-find.html' title='How To Use Fuzzy Look Up To Find The Sentence In Sql?'/><author><name>Blake Hickle</name><uri>http://www.blogger.com/profile/04290019036198769750</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7204472375574233207.post-2661677376509764453</id><published>2024-08-21T08:42:00.001-07:00</published><updated>2024-08-21T08:42:42.658-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><title type='text'>How To Generate Fibonacci Series</title><content type='html'>&lt;div class=&quot;question&quot;&gt;How to Generate Fibonacci series in sql ! I need to generate Fibonacci series 0 1 1 2 3  5 8 13 21 ... N I did this easily using C-code I need to do this using Sql !&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;&lt;strong&gt;Try This Simple Query:&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;1) For Result In Row-by-Row (Single Column, Multiple Rows)&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;WITH&lt;/span&gt; Fibonacci (PrevN, N) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt;
(
     &lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;
     UNION ALL
     &lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; N, PrevN + N
     &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; Fibonacci
     &lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt; N &amp;lt; &lt;span class=&quot;hljs-number&quot;&gt;1000000000&lt;/span&gt;
)
&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; PrevN &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt; Fibo
     &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; Fibonacci
     &lt;span class=&quot;hljs-keyword&quot;&gt;OPTION&lt;/span&gt; (MAXRECURSION &lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;);
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;&lt;em&gt;Output 1:&lt;/em&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;img alt=&quot;enter image description here&quot; src=&quot;https://i.stack.imgur.com/OL3fy.png&quot;&gt;&lt;/p&gt;&lt;p&gt;2) For Result in Only One Row (Comma sepreted, in Single Cell)&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_1&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;WITH&lt;/span&gt; Fibonacci (PrevN, N) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt;
(
 &lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;ALL&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; N, PrevN &lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt; N
    &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; Fibonacci
    &lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt; N &lt;span class=&quot;hljs-operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1000000000&lt;/span&gt;
)
&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;Substring&lt;/span&gt;(
    (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;cast&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot;&gt;&#39;, &#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;varchar&lt;/span&gt;(max)) &lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;cast&lt;/span&gt;(PrevN &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;varchar&lt;/span&gt;(max)
);
&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; Fibonacci
&lt;span class=&quot;hljs-keyword&quot;&gt;FOR&lt;/span&gt; XML PATH(&lt;span class=&quot;hljs-string&quot;&gt;&#39;&#39;&lt;/span&gt;)),&lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;,&lt;span class=&quot;hljs-number&quot;&gt;10000000&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; list
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_1&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;&lt;em&gt;Output 2:&lt;/em&gt;&lt;img alt=&quot;enter image description here&quot; src=&quot;https://i.stack.imgur.com/ujwGo.png&quot;&gt;&lt;/p&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Try this !&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_2&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;declare&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@a&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;declare&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@b&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;declare&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@c&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Declare&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@i&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@a&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@b&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@i&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@c&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;
Print &lt;span class=&quot;hljs-string&quot;&gt;&#39;Fibonacci Series&#39;&lt;/span&gt;
print &lt;span class=&quot;hljs-variable&quot;&gt;@a&lt;/span&gt;
print &lt;span class=&quot;hljs-variable&quot;&gt;@b&lt;/span&gt;
while &lt;span class=&quot;hljs-variable&quot;&gt;@i&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Begin&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@c&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@a&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@b&lt;/span&gt;
print &lt;span class=&quot;hljs-variable&quot;&gt;@c&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@i&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@i&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@a&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@b&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@b&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@c&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;end&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_2&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;h2&gt;Outputs !&lt;/h2&gt;&lt;pre&gt;&lt;code id=&quot;code_3&quot; class=&quot;hljs language-undefined&quot;&gt;Fibonacci Series
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_3&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;0
1
1
2
3
5
8
13
21
34
55
89&lt;/p&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_3&quot;&gt;Solution 3:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Please try:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_4&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; fib_number &lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;ALL&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;FLOOR&lt;/span&gt;(&lt;span class=&quot;hljs-built_in&quot;&gt;POWER&lt;/span&gt;(( &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;SQRT&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot;&gt;5&lt;/span&gt;) ) &lt;span class=&quot;hljs-operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;2.0&lt;/span&gt;, number) &lt;span class=&quot;hljs-operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;SQRT&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot;&gt;5&lt;/span&gt;) &lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0.5&lt;/span&gt;)
&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; master..spt_values
&lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt; TYPE &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;p&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;AND&lt;/span&gt; number &lt;span class=&quot;hljs-keyword&quot;&gt;BETWEEN&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;AND&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;70&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_4&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_4&quot;&gt;Solution 4:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Try this :-&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_5&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Declare&lt;/span&gt; @Fib int = &lt;span class=&quot;hljs-number&quot;&gt;5&lt;/span&gt;
 ;&lt;span class=&quot;hljs-keyword&quot;&gt;with&lt;/span&gt; cte &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt;
 (
   &lt;span class=&quot;hljs-keyword&quot;&gt;Select&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt; Previous,&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Next&lt;/span&gt; ,&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt; Level 
   union all
   &lt;span class=&quot;hljs-keyword&quot;&gt;Select&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Next&lt;/span&gt;,&lt;span class=&quot;hljs-keyword&quot;&gt;Next&lt;/span&gt; + Previous,Level +&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; cte 
   &lt;span class=&quot;hljs-keyword&quot;&gt;where&lt;/span&gt; Level +&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt; &amp;lt;@Fib
 )
 &lt;span class=&quot;hljs-keyword&quot;&gt;Select&lt;/span&gt; Previous &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt; FibonacciSeries &lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; cte
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_5&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_5&quot;&gt;Solution 5:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;This is for generating the first 10 numbers in the series.&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_6&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;DECLARE&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@NoOne&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;INT&lt;/span&gt;,  &lt;span class=&quot;hljs-variable&quot;&gt;@NoTwo&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;INT&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;DECLARE&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@FibonacciTable&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;TABLE&lt;/span&gt; (Number &lt;span class=&quot;hljs-type&quot;&gt;INT&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;NOT&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;NULL&lt;/span&gt;)
&lt;span class=&quot;hljs-comment&quot;&gt;--Insert first two numbers 0 and 1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;INSERT&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@FibonacciTable&lt;/span&gt; (Number) &lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;ALL&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@NoOne&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;hljs-variable&quot;&gt;@NoTwo&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;

WHILE (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;COUNT&lt;/span&gt;(&lt;span class=&quot;hljs-operator&quot;&gt;*&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@FibonacciTable&lt;/span&gt;) &lt;span class=&quot;hljs-operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;BEGIN&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;INSERT&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@FibonacciTable&lt;/span&gt; (Number) &lt;span class=&quot;hljs-keyword&quot;&gt;VALUES&lt;/span&gt;(&lt;span class=&quot;hljs-variable&quot;&gt;@NoOne&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@NoTwo&lt;/span&gt;)
    &lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@NoTwo&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@NoOne&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@NoTwo&lt;/span&gt;, &lt;span class=&quot;hljs-variable&quot;&gt;@NoOne&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@NoTwo&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@NoOne&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;END&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@FibonacciTable&lt;/span&gt;   
GO
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_6&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt; 

</content><link rel='replies' type='application/atom+xml' href='https://supers-affiliate.blogspot.com/feeds/2661677376509764453/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/how-to-generate-fibonacci-series.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/2661677376509764453'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/2661677376509764453'/><link rel='alternate' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/how-to-generate-fibonacci-series.html' title='How To Generate Fibonacci Series'/><author><name>Blake Hickle</name><uri>http://www.blogger.com/profile/04290019036198769750</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7204472375574233207.post-7530296089426833663</id><published>2024-08-21T08:24:00.001-07:00</published><updated>2024-08-21T08:24:35.045-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server 2008"/><title type='text'>Sql Server Char And Nchar Columns Search Differently</title><content type='html'>&lt;div class=&quot;question&quot;&gt;We have a strange problem.  We are upgrading JDE and the database schema is changing - some char columns are changing to nchar types.  However, we have found that some of the searc&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;From the documentation for &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://msdn.microsoft.com/en-us/library/ms179859.aspx&quot;&gt;LIKE (Transact-SQL)&lt;/a&gt;:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;When you use Unicode data (nchar or nvarchar data types) with LIKE, trailing blanks are significant; however, for non-Unicode data, trailing blanks are not significant. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;I reproduced your problem with the following table:&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;DECLARE&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@t&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;TABLE&lt;/span&gt;(x &lt;span class=&quot;hljs-type&quot;&gt;NCHAR&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot;&gt;25&lt;/span&gt;));
&lt;span class=&quot;hljs-keyword&quot;&gt;INSERT&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@t&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; N&lt;span class=&quot;hljs-string&quot;&gt;&#39;nanaS&#39;&lt;/span&gt;;
&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; x &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@t&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt; x &lt;span class=&quot;hljs-keyword&quot;&gt;LIKE&lt;/span&gt; N&lt;span class=&quot;hljs-string&quot;&gt;&#39;%S&#39;&lt;/span&gt;;
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Result:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_1&quot; class=&quot;hljs language-scss&quot;&gt;(&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt; row(s) affected)
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_1&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;However if you use &lt;code&gt;NVARCHAR&lt;/code&gt; instead, this problem does not occur:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_3&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;DECLARE&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@t&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;TABLE&lt;/span&gt;(x NVARCHAR(&lt;span class=&quot;hljs-number&quot;&gt;25&lt;/span&gt;));
&lt;span class=&quot;hljs-keyword&quot;&gt;INSERT&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@t&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; N&lt;span class=&quot;hljs-string&quot;&gt;&#39;nanaS&#39;&lt;/span&gt;;
&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; x &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@t&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt; x &lt;span class=&quot;hljs-keyword&quot;&gt;LIKE&lt;/span&gt; N&lt;span class=&quot;hljs-string&quot;&gt;&#39;%S&#39;&lt;/span&gt;;
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_3&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Results:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_4&quot; class=&quot;hljs language-markdown&quot;&gt;&lt;span class=&quot;hljs-section&quot;&gt;x
-----&lt;/span&gt;
nanaS
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_4&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;However the original table didn&#39;t produce the desired results even if converting to &lt;code&gt;NVARCHAR&lt;/code&gt; in the &lt;code&gt;WHERE&lt;/code&gt; clause:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_7&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;DECLARE&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@t&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;TABLE&lt;/span&gt;(x &lt;span class=&quot;hljs-type&quot;&gt;NCHAR&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot;&gt;25&lt;/span&gt;));
&lt;span class=&quot;hljs-keyword&quot;&gt;INSERT&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@t&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; N&lt;span class=&quot;hljs-string&quot;&gt;&#39;nanaS&#39;&lt;/span&gt;;
&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; x &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@t&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;CONVERT&lt;/span&gt;(NVARCHAR(&lt;span class=&quot;hljs-number&quot;&gt;25&lt;/span&gt;),x) &lt;span class=&quot;hljs-keyword&quot;&gt;LIKE&lt;/span&gt; N&lt;span class=&quot;hljs-string&quot;&gt;&#39;%S&#39;&lt;/span&gt;;
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_7&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Result:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_8&quot; class=&quot;hljs language-scss&quot;&gt;(&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt; row(s) affected)
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_8&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;So one potential workaround would be to use the right data type in the first place (and also always prefix Unicode strings &lt;code&gt;N&#39;properly&#39;&lt;/code&gt;. If you can&#39;t make the data type correct, you can use the &lt;code&gt;RTRIM()&lt;/code&gt; workaround posted by Aushin, but keep HLGEM&#39;s comments in mind as well.&lt;/p&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;EDIT: My explanation below was based of a misreading of your question. While RTRIM will work, I did not realize you weren&#39;t using nvarchar but char. Aaron and Gordon have provided better insight.&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_11&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; TableName &lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt; RTRIM(ItemNumber) &lt;span class=&quot;hljs-keyword&quot;&gt;LIKE&lt;/span&gt; N&lt;span class=&quot;hljs-string&quot;&gt;&#39;%S&#39;&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_11&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;blockquote&gt;&lt;p&gt;This is because for an nvarchar(25), the last character of
&#39;S&#39; is S. &lt;/p&gt;&lt;p&gt;For nchar(25), &#39;S&#39; is actually &#39;S&#39; + 24 spaces. So your last character
is a space.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt; 


</content><link rel='replies' type='application/atom+xml' href='https://supers-affiliate.blogspot.com/feeds/7530296089426833663/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/sql-server-char-and-nchar-columns.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/7530296089426833663'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/7530296089426833663'/><link rel='alternate' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/sql-server-char-and-nchar-columns.html' title='Sql Server Char And Nchar Columns Search Differently'/><author><name>Blake Hickle</name><uri>http://www.blogger.com/profile/04290019036198769750</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7204472375574233207.post-7509044940322020147</id><published>2024-08-21T08:04:00.001-07:00</published><updated>2024-08-21T08:04:45.628-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linked Server"/><category scheme="http://www.blogger.com/atom/ns#" term="Sp Executesql"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><category scheme="http://www.blogger.com/atom/ns#" term="Synonym"/><category scheme="http://www.blogger.com/atom/ns#" term="Tsql"/><title type='text'>How Do I Truncate A Table Via Linked Server Using A Synonym For The Table Name?</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I know I can do the following: EXEC Server_Name.DBName.sys.sp_executesql N&#39;TRUNCATE TABLE dbo.table_name&#39;  But what if I want to use a synonym for the table? I&#39;m on SERVER1 and I w&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;The link on the correct answer is broken. I ran into a similar problem. My workaround was using the synonyms table to lookup underlying table name, then running a dynamic sql statement. It is documented that synonyms cannot be used with TRUNCATE, but at least this is a decent workaround.&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;DECLARE&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@TableName&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;VARCHAR&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot;&gt;500&lt;/span&gt;) &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; TOP &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt; base_object_name
    &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; Server_Name.DBName.sys.synonyms &lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt; name &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;table_name&#39;&lt;/span&gt;)
&lt;span class=&quot;hljs-keyword&quot;&gt;DECLARE&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@Sql&lt;/span&gt; NVARCHAR(MAX) &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;EXEC Server_Name.DBName.sys.sp_executesql N&#39;&#39;TRUNCATE TABLE &#39;&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@TableName&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;&#39;&#39;&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;EXEC&lt;/span&gt; sys.sp_executesql &lt;span class=&quot;hljs-variable&quot;&gt;@Sql&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Create a Stored Procedure in Server2 Database for Truncate Tables then call the Stored Procedure from Server1.&lt;/p&gt;&lt;p&gt;Like this :-&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;EXEC [Server2].[DBName].[SchemaName].sp_TruncateTable;&lt;/p&gt;&lt;/div&gt; 


</content><link rel='replies' type='application/atom+xml' href='https://supers-affiliate.blogspot.com/feeds/7509044940322020147/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/how-do-i-truncate-table-via-linked.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/7509044940322020147'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/7509044940322020147'/><link rel='alternate' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/how-do-i-truncate-table-via-linked.html' title='How Do I Truncate A Table Via Linked Server Using A Synonym For The Table Name?'/><author><name>Blake Hickle</name><uri>http://www.blogger.com/profile/04290019036198769750</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7204472375574233207.post-2073302779880660890</id><published>2024-08-21T07:46:00.001-07:00</published><updated>2024-08-21T07:46:59.128-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Postgresql"/><category scheme="http://www.blogger.com/atom/ns#" term="Regex"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><title type='text'>Why Won&#39;t This Regex Work In Postgresql</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I&#39;m trying to get a regex to capture the base URL from a URL string. This ^(.+?[^\/:])(?=[?\/]|$)  works. REGEX101 But when I try to use it within postgresql  regexp_replace(conten&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;&lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://www.regexbuddy.com/postgresql.html&quot;&gt;RegexBuddy&lt;/a&gt; gives this warning about the first &#39;?&#39;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;PostgreSQL is inconsistent in the way it handles lazy quantifiers in
regular expressions with alternation because it attempts to match the
longest alternative, instead of being eager and accepting the first
alternative that matches&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;and if you remove it, it seems to work, i.e &lt;code&gt;^(.+[^\/:])(?=[?\/]|$)&lt;/code&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;however, if you&#39;re trying to parse the baseurl that regex won&#39;t work. Use this instead:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_1&quot; class=&quot;hljs language-csharp&quot;&gt;&lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-title&quot;&gt;regexp_replace&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot;&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;....&#39;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#39;^(.*:)//([a-z\-.]+)(:[0-9]+)?(.*)$&#39;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#39;\2&#39;&lt;/span&gt;&lt;/span&gt;)
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_1&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;PostGreSQL has an interesting regular expression engine. It took me a while to figure out what be escaped and what needs to be double-escaped. The solution that worked for me is:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_2&quot; class=&quot;hljs language-php&quot;&gt;(regexp_matches(content_url,&lt;span class=&quot;hljs-string&quot;&gt;&#39;(https?:\/\/\\w+(?:\\.\\w+)+)&#39;&lt;/span&gt;))[&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;] &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; content_url
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_2&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Hope this can help someone. &lt;/p&gt;&lt;/div&gt; 


</content><link rel='replies' type='application/atom+xml' href='https://supers-affiliate.blogspot.com/feeds/2073302779880660890/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/why-wont-this-regex-work-in-postgresql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/2073302779880660890'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/2073302779880660890'/><link rel='alternate' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/why-wont-this-regex-work-in-postgresql.html' title='Why Won&#39;t This Regex Work In Postgresql'/><author><name>Blake Hickle</name><uri>http://www.blogger.com/profile/04290019036198769750</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7204472375574233207.post-1449162006288357062</id><published>2024-08-21T07:10:00.001-07:00</published><updated>2024-08-21T07:10:33.714-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Mysql"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><title type='text'>Select Distinct Only First Four Numbers</title><content type='html'>&lt;div class=&quot;question&quot;&gt;Consider the following table: ticker  code -------------- AA      151040 AAP     452020 DOW     151010 DVN     151020 EXC     452050 FAD     452070 POE     207010  I would like to&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Use &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_left&quot;&gt;&lt;code&gt;LEFT&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_1&quot; class=&quot;hljs language-css&quot;&gt;SELECT &lt;span class=&quot;hljs-attribute&quot;&gt;LEFT&lt;/span&gt;(&lt;span class=&quot;hljs-selector-tag&quot;&gt;code&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot;&gt;4&lt;/span&gt;) AS &lt;span class=&quot;hljs-selector-tag&quot;&gt;code&lt;/span&gt;, ticker &lt;span class=&quot;hljs-selector-tag&quot;&gt;FROM&lt;/span&gt; tbl &lt;span class=&quot;hljs-attribute&quot;&gt;ORDER&lt;/span&gt; BY &lt;span class=&quot;hljs-selector-tag&quot;&gt;code&lt;/span&gt;;
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_1&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;pre&gt;&lt;code id=&quot;code_2&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;SUBSTRING&lt;/span&gt;(code,&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;hljs-number&quot;&gt;5&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; SUB_CODE,ticker
&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;TABLE&lt;/span&gt;;
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_2&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_3&quot;&gt;Solution 3:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;You can use Left function in mySql to select the first four Left(code,4) Then use order by. &lt;/p&gt;&lt;/div&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='https://supers-affiliate.blogspot.com/feeds/1449162006288357062/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/select-distinct-only-first-four-numbers.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/1449162006288357062'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/1449162006288357062'/><link rel='alternate' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/select-distinct-only-first-four-numbers.html' title='Select Distinct Only First Four Numbers'/><author><name>Blake Hickle</name><uri>http://www.blogger.com/profile/04290019036198769750</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7204472375574233207.post-2069016152561294603</id><published>2024-08-21T05:37:00.001-07:00</published><updated>2024-08-21T05:37:07.978-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Oracle"/><category scheme="http://www.blogger.com/atom/ns#" term="Oracle11g"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><title type='text'>Convert A Series Of Number Values In Text In Oracle Sql Query</title><content type='html'>&lt;div class=&quot;question&quot;&gt;In the Oracle database, I have string values (VARCHAR2) like 1,4,7,8. The number represents as 1=car, 2= bus, 3=BB, 4=SB, 5=Ba, 6=PA, 7=HB, and 8 =G and want to convert the above-s&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Here&#39;s one option. Read comments within code. Sample data in lines #1 - 13; query begins at line #14.&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SQL&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;with&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;  expl (id, name) &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;    (&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#39;car&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; dual &lt;span class=&quot;hljs-keyword&quot;&gt;union&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#39;bus&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; dual &lt;span class=&quot;hljs-keyword&quot;&gt;union&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#39;BB&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; dual &lt;span class=&quot;hljs-keyword&quot;&gt;union&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;4&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#39;SB&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; dual &lt;span class=&quot;hljs-keyword&quot;&gt;union&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;5&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#39;Ba&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; dual &lt;span class=&quot;hljs-keyword&quot;&gt;union&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;6&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#39;PA&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; dual &lt;span class=&quot;hljs-keyword&quot;&gt;union&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;7&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#39;HB&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; dual &lt;span class=&quot;hljs-keyword&quot;&gt;union&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;8&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#39;G&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; dual
 &lt;span class=&quot;hljs-number&quot;&gt;11&lt;/span&gt;    ),
 &lt;span class=&quot;hljs-number&quot;&gt;12&lt;/span&gt;  temp (col) &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;13&lt;/span&gt;    (&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;1,4,7,8&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; dual),
 &lt;span class=&quot;hljs-number&quot;&gt;14&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;-- split COL to rows&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;15&lt;/span&gt;  spl &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;16&lt;/span&gt;    (&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt; regexp_substr(col, &lt;span class=&quot;hljs-string&quot;&gt;&#39;[^,]+&#39;&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;, level) val,
 &lt;span class=&quot;hljs-number&quot;&gt;17&lt;/span&gt;            level lvl
 &lt;span class=&quot;hljs-number&quot;&gt;18&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; temp
 &lt;span class=&quot;hljs-number&quot;&gt;19&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;connect&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;by&lt;/span&gt; level &lt;span class=&quot;hljs-operator&quot;&gt;&amp;lt;=&lt;/span&gt; regexp_count(col, &lt;span class=&quot;hljs-string&quot;&gt;&#39;,&#39;&lt;/span&gt;) &lt;span class=&quot;hljs-operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;20&lt;/span&gt;    )
 &lt;span class=&quot;hljs-number&quot;&gt;21&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;-- join SPL with EXPL; aggregate the result&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;22&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;listagg&lt;/span&gt;(e.name, &lt;span class=&quot;hljs-string&quot;&gt;&#39;,&#39;&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot;&gt;within&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;group&lt;/span&gt; (&lt;span class=&quot;hljs-keyword&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;by&lt;/span&gt; s.lvl) &lt;span class=&quot;hljs-keyword&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;23&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; expl e &lt;span class=&quot;hljs-keyword&quot;&gt;join&lt;/span&gt; spl s &lt;span class=&quot;hljs-keyword&quot;&gt;on&lt;/span&gt; s.val &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; e.id;

&lt;span class=&quot;hljs-keyword&quot;&gt;RESULT&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;--------------------------------------------------------------------------------&lt;/span&gt;
car,SB,HB,G

&lt;span class=&quot;hljs-keyword&quot;&gt;SQL&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Using the function &lt;code&gt;f_subst&lt;/code&gt; from &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://stackoverflow.com/a/68537479/429100&quot;&gt;https://stackoverflow.com/a/68537479/429100&lt;/a&gt; :&lt;/p&gt;&lt;pre class=&quot;lang-sql prettyprint-override&quot;&gt;&lt;code id=&quot;code_2&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;or&lt;/span&gt; replace
&lt;span class=&quot;hljs-keyword&quot;&gt;function&lt;/span&gt; f_subst(str varchar2, template varchar2, subst sys.odcivarchar2list) &lt;span class=&quot;hljs-keyword&quot;&gt;return&lt;/span&gt; varchar2
&lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt;
    res varchar2(&lt;span class=&quot;hljs-number&quot;&gt;32767&lt;/span&gt;):&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;str;
&lt;span class=&quot;hljs-keyword&quot;&gt;begin&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;for&lt;/span&gt; i &lt;span class=&quot;hljs-keyword&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1.&lt;/span&gt;.subst.count loop
        res:&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;replace(res, replace(template,&lt;span class=&quot;hljs-string&quot;&gt;&#39;%d&#39;&lt;/span&gt;,i), subst(i));
    &lt;span class=&quot;hljs-keyword&quot;&gt;end&lt;/span&gt; loop;
    &lt;span class=&quot;hljs-keyword&quot;&gt;return&lt;/span&gt; res;
&lt;span class=&quot;hljs-keyword&quot;&gt;end&lt;/span&gt;;
&lt;span class=&quot;hljs-operator&quot;&gt;/&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_2&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;I&#39;ve replaced &lt;code&gt;ora_name_list_t&lt;/code&gt; (nested table) with &lt;code&gt;sys.odcivarchar2list&lt;/code&gt; (varray) to make this example easier, but I would suggest to create your own collection for example &lt;code&gt;create type varchar2_table as table of varchar2(4000);&lt;/code&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_6&quot; class=&quot;hljs language-csharp&quot;&gt;&lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-title&quot;&gt;f_subst&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot;&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;1,4,7,8&#39;&lt;/span&gt;
     ,&lt;span class=&quot;hljs-string&quot;&gt;&#39;%d&#39;&lt;/span&gt;
     ,sys.odcivarchar2list(&lt;span class=&quot;hljs-string&quot;&gt;&#39;car&#39;&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot;&gt;&#39;bus&#39;&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot;&gt;&#39;BB&#39;&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot;&gt;&#39;SB&#39;&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot;&gt;&#39;Ba&#39;&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot;&gt;&#39;PA&#39;&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot;&gt;&#39;HB&#39;&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot;&gt;&#39;G&#39;&lt;/span&gt;&lt;/span&gt;)
   ) s 
&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; dual&lt;/span&gt;; 

S
----------------------------------------
car,SB,HB,G
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_6&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_3&quot;&gt;Solution 3:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Assume you have a lookup table (associating the numeric codes with descriptions) and a table of input strings, which I called &lt;code&gt;sample_inputs&lt;/code&gt; in my tests, as shown below:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_8&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;table&lt;/span&gt; lookup (code, descr) &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#39;car&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; dual &lt;span class=&quot;hljs-keyword&quot;&gt;union&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#39;bus&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; dual &lt;span class=&quot;hljs-keyword&quot;&gt;union&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#39;BB&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; dual &lt;span class=&quot;hljs-keyword&quot;&gt;union&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;4&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#39;SB&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; dual &lt;span class=&quot;hljs-keyword&quot;&gt;union&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;5&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#39;Ba&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; dual &lt;span class=&quot;hljs-keyword&quot;&gt;union&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;6&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#39;PA&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; dual &lt;span class=&quot;hljs-keyword&quot;&gt;union&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;7&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#39;HB&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; dual &lt;span class=&quot;hljs-keyword&quot;&gt;union&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;8&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#39;G&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; dual
;

&lt;span class=&quot;hljs-keyword&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;table&lt;/span&gt; sample_inputs (str) &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;1,4,7,8&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; dual &lt;span class=&quot;hljs-keyword&quot;&gt;union&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; dual &lt;span class=&quot;hljs-keyword&quot;&gt;union&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;3&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; dual &lt;span class=&quot;hljs-keyword&quot;&gt;union&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;5,5,5&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; dual &lt;span class=&quot;hljs-keyword&quot;&gt;union&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;6,2,8&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; dual
;
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_8&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;One strategy for solving your problem is to split the input - slightly modified to make it a JSON array, so that we can use &lt;code&gt;json_table&lt;/code&gt; to split it - then join to the lookup table and re-aggregate.&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_10&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt; s.str, l.descr_list
&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt;   sample_inputs s &lt;span class=&quot;hljs-keyword&quot;&gt;cross&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;lateral&lt;/span&gt;
       ( &lt;span class=&quot;hljs-keyword&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;listagg&lt;/span&gt;(descr, &lt;span class=&quot;hljs-string&quot;&gt;&#39;,&#39;&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot;&gt;within&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;group&lt;/span&gt; (&lt;span class=&quot;hljs-keyword&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;by&lt;/span&gt; ord) &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt; descr_list
         &lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;json_table&lt;/span&gt;( &lt;span class=&quot;hljs-string&quot;&gt;&#39;[&#39;&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;||&lt;/span&gt; str &lt;span class=&quot;hljs-operator&quot;&gt;||&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;]&#39;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#39;$[*]&#39;&lt;/span&gt;
                            columns code number path &lt;span class=&quot;hljs-string&quot;&gt;&#39;$&#39;&lt;/span&gt;, ord &lt;span class=&quot;hljs-keyword&quot;&gt;for&lt;/span&gt; ordinality)
                &lt;span class=&quot;hljs-keyword&quot;&gt;join&lt;/span&gt; lookup l &lt;span class=&quot;hljs-keyword&quot;&gt;using&lt;/span&gt; (code)
       ) l
;

STR     DESCR_LIST                    
&lt;span class=&quot;hljs-comment&quot;&gt;------- ------------------------------&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;hljs-number&quot;&gt;4&lt;/span&gt;,&lt;span class=&quot;hljs-number&quot;&gt;7&lt;/span&gt;,&lt;span class=&quot;hljs-number&quot;&gt;8&lt;/span&gt; car,SB,HB,G                   
                                      
&lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;       BB                            
&lt;span class=&quot;hljs-number&quot;&gt;5&lt;/span&gt;,&lt;span class=&quot;hljs-number&quot;&gt;5&lt;/span&gt;,&lt;span class=&quot;hljs-number&quot;&gt;5&lt;/span&gt;   Ba,Ba,Ba                      
&lt;span class=&quot;hljs-number&quot;&gt;6&lt;/span&gt;,&lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;,&lt;span class=&quot;hljs-number&quot;&gt;8&lt;/span&gt;   PA,bus,G   
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_10&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt; 

</content><link rel='replies' type='application/atom+xml' href='https://supers-affiliate.blogspot.com/feeds/2069016152561294603/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/convert-series-of-number-values-in-text.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/2069016152561294603'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/2069016152561294603'/><link rel='alternate' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/convert-series-of-number-values-in-text.html' title='Convert A Series Of Number Values In Text In Oracle Sql Query'/><author><name>Blake Hickle</name><uri>http://www.blogger.com/profile/04290019036198769750</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7204472375574233207.post-7762288683035905328</id><published>2024-08-21T05:18:00.001-07:00</published><updated>2024-08-21T05:18:36.099-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Alter Table"/><category scheme="http://www.blogger.com/atom/ns#" term="Datetime Format"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><title type='text'>How To Change Date Format Of Datetime Data Type In Sql?</title><content type='html'>&lt;div class=&quot;question&quot;&gt;My date format of &#39;03-01-2017 10:24:48&#39; is getting stored in SQL as &#39;2017-03-01 10:24:48.000&#39; where my &#39;dd-mm-yyyy&#39; format is getting converted to &#39;yyyy-mm-dd&#39; format. How can I ch&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot; style=&quot;height: auto !important;&quot;&gt;&lt;p&gt;SQL Server doesn&#39;t store a &lt;code&gt;DateTime&lt;/code&gt; in any string format - it&#39;s stored as an &lt;strong&gt;8 byte numerical&lt;/strong&gt; (binary) value.&lt;/p&gt;&lt;p&gt;The various settings (language, date format) only influence how the &lt;code&gt;DateTime&lt;/code&gt; is shown to you in SQL Server Management Studio - or how it is parsed when you attempt to convert a string to a &lt;code&gt;DateTime&lt;/code&gt;. &lt;/p&gt;&lt;p&gt;There are many formats supported by SQL Server - see the &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://msdn.microsoft.com/en-us/library/ms187928.aspx&quot;&gt;MSDN Books Online on CAST and CONVERT&lt;/a&gt;. Most of those formats are &lt;strong&gt;dependent&lt;/strong&gt; on what settings you have - therefore, these settings might work some times - and sometimes not.&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;The way to solve this is to use the (slightly adapted) &lt;strong&gt;ISO-8601 date format&lt;/strong&gt; that is supported by SQL Server - this format works &lt;strong&gt;always&lt;/strong&gt; - regardless of your SQL Server language and dateformat settings.&lt;/p&gt;&lt;p&gt;The &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://msdn.microsoft.com/en-us/library/ms180878.aspx&quot;&gt;ISO-8601 format&lt;/a&gt; is supported by SQL Server comes in two flavors:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;code&gt;YYYYMMDD&lt;/code&gt; for just dates (no time portion); note here: &lt;strong&gt;no dashes!&lt;/strong&gt;, that&#39;s very important! &lt;code&gt;YYYY-MM-DD&lt;/code&gt; is &lt;strong&gt;NOT&lt;/strong&gt; independent of the dateformat settings in your SQL Server and will &lt;strong&gt;NOT&lt;/strong&gt; work in all situations!&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;or:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;code&gt;YYYY-MM-DDTHH:MM:SS&lt;/code&gt; for dates and times - note here: this format &lt;em&gt;has&lt;/em&gt; dashes (but they &lt;em&gt;can&lt;/em&gt; be omitted), and a fixed &lt;code&gt;T&lt;/code&gt; as delimiter between the date and time portion of your &lt;code&gt;DATETIME&lt;/code&gt;.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;This is valid for SQL Server 2000 and newer.&lt;/p&gt;&lt;p&gt;If you use SQL Server 2008 or newer and the &lt;code&gt;DATE&lt;/code&gt; datatype (only &lt;code&gt;DATE&lt;/code&gt; - &lt;strong&gt;not&lt;/strong&gt;&lt;code&gt;DATETIME&lt;/code&gt;!), then you can indeed also use the &lt;code&gt;YYYY-MM-DD&lt;/code&gt; format and that will work, too, with any settings in your SQL Server.&lt;/p&gt;&lt;p&gt;Don&#39;t ask me why this whole topic is so tricky and somewhat confusing - that&#39;s just the way it is. But with the &lt;code&gt;YYYYMMDD&lt;/code&gt; format, you should be fine for any version of SQL Server and for any language and dateformat setting in your SQL Server.&lt;/p&gt;&lt;p&gt;The recommendation for SQL Server 2008 and newer is to use &lt;code&gt;DATE&lt;/code&gt; if you only need the date portion, and &lt;code&gt;DATETIME2(n)&lt;/code&gt; when you need both date and time. You should try to start phasing out the &lt;code&gt;DATETIME&lt;/code&gt; datatype if ever possible&lt;/p&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Changing the format does not change the way the data is stored, just the way it is displayed. You can find date and time styles at &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://msdn.microsoft.com/en-us/library/ms187928.aspx?f=255&amp;amp;MSPPError=-2147217396&quot;&gt;https://msdn.microsoft.com/en-us/library/ms187928.aspx?f=255&amp;amp;MSPPError=-2147217396&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt; 


</content><link rel='replies' type='application/atom+xml' href='https://supers-affiliate.blogspot.com/feeds/7762288683035905328/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/how-to-change-date-format-of-datetime.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/7762288683035905328'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/7762288683035905328'/><link rel='alternate' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/how-to-change-date-format-of-datetime.html' title='How To Change Date Format Of Datetime Data Type In Sql?'/><author><name>Blake Hickle</name><uri>http://www.blogger.com/profile/04290019036198769750</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7204472375574233207.post-5728128624833570792</id><published>2024-08-21T04:23:00.001-07:00</published><updated>2024-08-21T04:23:56.312-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ms Access"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><title type='text'>Simple Sql Query In Access</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I need some help with figuring out two queries I am trying out from my textbook. I can&#39;t seem to figure them out. Any help would be appreciated! The first query deals with getting&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Well you can actually use the &#39;TOP&#39; keyword if you are using the JET Engine.&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; TOP &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt; Location
&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; Casino
&lt;span class=&quot;hljs-keyword&quot;&gt;GROUP&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;BY&lt;/span&gt; Location
&lt;span class=&quot;hljs-keyword&quot;&gt;ORDER&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;By&lt;/span&gt; Location;
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;For the next one, can you post the table and attributes?&lt;/p&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;(Please Note : This is an edited version of my original answer which was corrected to remove a bug I identified after posting which would list, for example, Players who had played at three Casinos one slot machine that had been played at all Casinos and at four Casinos a second similarly qualified Slot machine. It would also fail to list Players who had played a qualified Slot machine at all Casinos if they had also played at least one other qualified Slot machine.&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;This edited version has been tested on an expanded dataset. It will list list only Players who have Played any particular Slot at each of the Casinos at least once. It should also be easier to understand.)&lt;/p&gt;&lt;p&gt;As for your second problem, I suggest the following as a soultion...&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_1&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;DISTINCT&lt;/span&gt; PlayerNum
&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; PlayerNum, SlotNum, &lt;span class=&quot;hljs-built_in&quot;&gt;Count&lt;/span&gt;(&lt;span class=&quot;hljs-operator&quot;&gt;*&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; CountSlot
      &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; Plays
      &lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt; SlotNum &lt;span class=&quot;hljs-keyword&quot;&gt;IN&lt;/span&gt; 
          (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; SlotNum
           &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt;
               (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;DISTINCT&lt;/span&gt; SlotNum, CasinoNum
                &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; Plays) SlotCasino
           &lt;span class=&quot;hljs-keyword&quot;&gt;GROUP&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;BY&lt;/span&gt; SlotNum
           &lt;span class=&quot;hljs-keyword&quot;&gt;HAVING&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;COUNT&lt;/span&gt;(CasinoNum) &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;
              (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;COUNT&lt;/span&gt;(CasinoNum)
               &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; Casino))
      &lt;span class=&quot;hljs-keyword&quot;&gt;GROUP&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;BY&lt;/span&gt; PlayerNum, SlotNum) EligiblePlayers
&lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt; CountSlot &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;COUNT&lt;/span&gt;(CasinoNum)
                   &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; Casino);
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_1&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;The logic that I followed was that I should determine which Slots had been played at all the Casinos and which Players had played those Slots at all of the Casinos.&lt;/p&gt;&lt;p&gt;To figure out which Slots had been played at all the Casinos I first isolated all combinations of Slot played and Casinos played at using -&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_2&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;DISTINCT&lt;/span&gt; SlotNum, CasinoNum
&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; Plays
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_2&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;I then found out which Slots had been played at each of the current number of Casinos using -&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_3&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; SlotNum
&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt;
    (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;DISTINCT&lt;/span&gt; SlotNum, CasinoNum
    &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; Plays) SlotCasino
    &lt;span class=&quot;hljs-keyword&quot;&gt;GROUP&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;BY&lt;/span&gt; SlotNum
    &lt;span class=&quot;hljs-keyword&quot;&gt;HAVING&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;COUNT&lt;/span&gt;(CasinoNum) &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;
        (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;COUNT&lt;/span&gt;(CasinoNum)
        &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; Casino)
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_3&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;I then found out which Players had Played on these Slots and at how many Casinos using -&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_4&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; PlayerNum, SlotNum, &lt;span class=&quot;hljs-built_in&quot;&gt;Count&lt;/span&gt;(&lt;span class=&quot;hljs-operator&quot;&gt;*&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; CountSlot
&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; Plays
&lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt; SlotNum &lt;span class=&quot;hljs-keyword&quot;&gt;IN&lt;/span&gt; 
    (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; SlotNum
     &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt;
         (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;DISTINCT&lt;/span&gt; SlotNum, CasinoNum
          &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; Plays) SlotCasino
     &lt;span class=&quot;hljs-keyword&quot;&gt;GROUP&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;BY&lt;/span&gt; SlotNum
     &lt;span class=&quot;hljs-keyword&quot;&gt;HAVING&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;COUNT&lt;/span&gt;(CasinoNum) &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;
        (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;COUNT&lt;/span&gt;(CasinoNum)
         &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; Casino))
&lt;span class=&quot;hljs-keyword&quot;&gt;GROUP&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;BY&lt;/span&gt; PlayerNum, SlotNum
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_4&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;I refined this list to only Players who have Played a qualified Slot at each of the Casinos using -&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_5&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;DISTINCT&lt;/span&gt; PlayerNum
&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; PlayerNum, SlotNum, &lt;span class=&quot;hljs-built_in&quot;&gt;Count&lt;/span&gt;(&lt;span class=&quot;hljs-operator&quot;&gt;*&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; CountSlot
      &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; Plays
      &lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt; SlotNum &lt;span class=&quot;hljs-keyword&quot;&gt;IN&lt;/span&gt; 
          (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; SlotNum
           &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt;
               (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;DISTINCT&lt;/span&gt; SlotNum, CasinoNum
                &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; Plays) SlotCasino
           &lt;span class=&quot;hljs-keyword&quot;&gt;GROUP&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;BY&lt;/span&gt; SlotNum
           &lt;span class=&quot;hljs-keyword&quot;&gt;HAVING&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;COUNT&lt;/span&gt;(CasinoNum) &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;
              (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;COUNT&lt;/span&gt;(CasinoNum)
               &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; Casino))
      &lt;span class=&quot;hljs-keyword&quot;&gt;GROUP&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;BY&lt;/span&gt; PlayerNum, SlotNum) EligiblePlayers
&lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt; CountSlot &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; (&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;COUNT&lt;/span&gt;(CasinoNum)
                   &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; Casino);
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_5&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;I hope that I have explained this adequately. If not, or if you have any other questions, then please feel free to reply.&lt;/p&gt;&lt;/div&gt; 


</content><link rel='replies' type='application/atom+xml' href='https://supers-affiliate.blogspot.com/feeds/5728128624833570792/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/simple-sql-query-in-access.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/5728128624833570792'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/5728128624833570792'/><link rel='alternate' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/simple-sql-query-in-access.html' title='Simple Sql Query In Access'/><author><name>Blake Hickle</name><uri>http://www.blogger.com/profile/04290019036198769750</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7204472375574233207.post-5504328884290264278</id><published>2024-08-21T03:47:00.001-07:00</published><updated>2024-08-21T03:47:06.662-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="Linq To Sql"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><title type='text'>Linq To Sql Not Inserting Data Onto The Db</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I have a little / weird behaviour here and Im looking over internet and SO and I didn&#39;t find a response. I have to admit that this is my first time using databases, I know how to u&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;First; do you have a &lt;code&gt;TransactionScope&lt;/code&gt; that spans this, that you haven&#39;t committed.&lt;/p&gt;&lt;p&gt;However, more liktely: is this a database &lt;em&gt;file&lt;/em&gt; that you are deploying with the system (rather than a separate database server)? If so, every time you hit &quot;build&quot; etc, it copies the version from your solution folder into the build output (bin/debug or bin/release).&lt;/p&gt;&lt;p&gt;Look in the build output copy; see if &lt;em&gt;that&lt;/em&gt; has been updated.&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt; 

</content><link rel='replies' type='application/atom+xml' href='https://supers-affiliate.blogspot.com/feeds/5504328884290264278/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/linq-to-sql-not-inserting-data-onto-db.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/5504328884290264278'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/5504328884290264278'/><link rel='alternate' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/linq-to-sql-not-inserting-data-onto-db.html' title='Linq To Sql Not Inserting Data Onto The Db'/><author><name>Blake Hickle</name><uri>http://www.blogger.com/profile/04290019036198769750</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7204472375574233207.post-2058863940633173789</id><published>2024-08-21T03:29:00.001-07:00</published><updated>2024-08-21T03:29:07.161-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Database Project"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><category scheme="http://www.blogger.com/atom/ns#" term="Visual Studio 2012"/><title type='text'>Can I Ignore Logins When Publishing A Visual Studio Database Project?</title><content type='html'>&lt;div class=&quot;question&quot;&gt;We have a SQL Server that uses SQL Server Authentication, with users that can deploy, and others that can read, for the sake of simplicity, I&#39;ll call them &#39;deploy&#39; and &#39;web&#39;. I&#39;m h&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;As the user already exists, I suspect that the user that is used to perform the deploy doesn&#39;t have rights to view it. The below should be all you need to resolve this.&lt;/p&gt;&lt;p&gt;&lt;code&gt;GRANT VIEW DEFINITION ON LOGIN::web TO deploy&lt;/code&gt;&lt;/p&gt;&lt;/div&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='https://supers-affiliate.blogspot.com/feeds/2058863940633173789/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/can-i-ignore-logins-when-publishing.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/2058863940633173789'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/2058863940633173789'/><link rel='alternate' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/can-i-ignore-logins-when-publishing.html' title='Can I Ignore Logins When Publishing A Visual Studio Database Project?'/><author><name>Blake Hickle</name><uri>http://www.blogger.com/profile/04290019036198769750</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7204472375574233207.post-3875199974474482778</id><published>2024-08-21T02:35:00.001-07:00</published><updated>2024-08-21T02:35:37.545-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Hibernate"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><title type='text'>Geting &#39;entity Class Not Found&#39; Error While Mapping Classes To Database Table By Hibernate</title><content type='html'>&lt;div class=&quot;question&quot;&gt;Simple pojo class package practice041116; public class Cls { public String name; public int roll; public Cls(){} public String getName() { return name; } public void setName(String&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;In your mapping file :&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-cpp&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-keyword&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;hljs-title class_&quot;&gt;name&lt;/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;Cls&quot;&lt;/span&gt; table=&lt;span class=&quot;hljs-string&quot;&gt;&quot;cls&quot;&lt;/span&gt;&amp;gt;
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;you don&#39;t specify qualified class name but just simple class name.
You should replace by :&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_1&quot; class=&quot;hljs language-cpp&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-keyword&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;hljs-title class_&quot;&gt;name&lt;/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;practice041116.Cls&quot;&lt;/span&gt; table=&lt;span class=&quot;hljs-string&quot;&gt;&quot;cls&quot;&lt;/span&gt;&amp;gt;
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_1&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Hibernate is an ORM framework which maps a Java Object (Entity Object) to a relational database table, as you did NOT map any Entity Class to a database table you are getting this exception.&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;strong&gt;Option(1): Using Annotations&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;You need to use &lt;code&gt;@Entity&lt;/code&gt; (class level mapping) and &lt;code&gt;@Column&lt;/code&gt; (element level mapping) to map the java object to a database table.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Option(2): Using mapping xml files&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;As sugested by David above and also you can look at &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://docs.jboss.org/hibernate/stable/annotations/reference/en/html/entity.html&quot;&gt;here&lt;/a&gt;&lt;/p&gt;&lt;/div&gt; 


</content><link rel='replies' type='application/atom+xml' href='https://supers-affiliate.blogspot.com/feeds/3875199974474482778/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/geting-entity-class-not-found-error.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/3875199974474482778'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/3875199974474482778'/><link rel='alternate' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/geting-entity-class-not-found-error.html' title='Geting &#39;entity Class Not Found&#39; Error While Mapping Classes To Database Table By Hibernate'/><author><name>Blake Hickle</name><uri>http://www.blogger.com/profile/04290019036198769750</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7204472375574233207.post-1325398164760810689</id><published>2024-08-21T01:59:00.001-07:00</published><updated>2024-08-21T01:59:28.301-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><title type='text'>Delete From A Table Based On Date</title><content type='html'>&lt;div class=&quot;question&quot;&gt;Can anyone help me with the script which will delete the data older than the particular date. Thanks&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;delete&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; YOUR_TABLE &lt;span class=&quot;hljs-keyword&quot;&gt;where&lt;/span&gt; your_date_column &lt;span class=&quot;hljs-operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;2009-01-01&#39;&lt;/span&gt;;
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;This will delete rows from &lt;code&gt;YOUR_TABLE&lt;/code&gt; where the date in &lt;code&gt;your_date_column&lt;/code&gt; is older than January 1st, 2009. i.e. a date with &lt;code&gt;2008-12-31&lt;/code&gt; would be deleted. &lt;/p&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Delete data that is 30 days and older&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_4&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;DELETE&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Table&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt; DateColumn &lt;span class=&quot;hljs-operator&quot;&gt;&amp;lt;&lt;/span&gt; GETDATE()&lt;span class=&quot;hljs-operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;30&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_4&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_3&quot;&gt;Solution 3:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;You could use:&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;pre&gt;&lt;code id=&quot;code_5&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;DELETE&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; tableName
&lt;span class=&quot;hljs-keyword&quot;&gt;where&lt;/span&gt; your_date_column &lt;span class=&quot;hljs-operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;2009-01-01&#39;&lt;/span&gt;;
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_5&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;but Keep in mind that the above is really &lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_6&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;DELETE&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; tableName
    &lt;span class=&quot;hljs-keyword&quot;&gt;where&lt;/span&gt; your_date_column &lt;span class=&quot;hljs-operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;2009-01-01 00:00:00&#39;&lt;/span&gt;;
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_6&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Not&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_7&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;DELETE&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; tableName
        &lt;span class=&quot;hljs-keyword&quot;&gt;where&lt;/span&gt; your_date_column &lt;span class=&quot;hljs-operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;2009-01-01 11:59&#39;&lt;/span&gt;;
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_7&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_4&quot;&gt;Solution 4:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;or an ORACLE version:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_8&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;delete&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; table_name
 &lt;span class=&quot;hljs-keyword&quot;&gt;where&lt;/span&gt; trunc(table_name.date) &lt;span class=&quot;hljs-operator&quot;&gt;&amp;gt;&lt;/span&gt; to_date(&lt;span class=&quot;hljs-string&quot;&gt;&#39;01/01/2009&#39;&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot;&gt;&#39;mm/dd/yyyy&#39;&lt;/span&gt;) 
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_8&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_5&quot;&gt;Solution 5:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;This is pretty vague.
Do you mean like in SQL:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_9&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;DELETE&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; myTable
&lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt; dateColumn &lt;span class=&quot;hljs-operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;2007&#39;&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_9&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt; 

</content><link rel='replies' type='application/atom+xml' href='https://supers-affiliate.blogspot.com/feeds/1325398164760810689/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/delete-from-table-based-on-date.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/1325398164760810689'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/1325398164760810689'/><link rel='alternate' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/delete-from-table-based-on-date.html' title='Delete From A Table Based On Date'/><author><name>Blake Hickle</name><uri>http://www.blogger.com/profile/04290019036198769750</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7204472375574233207.post-3645919077581800283</id><published>2024-08-21T01:03:00.001-07:00</published><updated>2024-08-21T01:03:48.649-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Entity Framework"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server 2008"/><category scheme="http://www.blogger.com/atom/ns#" term="Xml"/><title type='text'>Saving Xml Contents With Iso-8859-1 Encoding Using Entity Framework Into Sql Server 2008&#39;s Xml Column Gives Encoding Error</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I am trying to save XML content with encoding=&#39;ISO-8859-1&#39; standalone=&#39;yes&#39; into a SQL Server 2008 XML column. I am doing this using Entity Framework.  However doing this throws th&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;The encoding width must match the datatype width&lt;/p&gt;&lt;p&gt;So &lt;em&gt;don&#39;t&lt;/em&gt; send:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;UTF-8 and nvarchar/xml&lt;/li&gt;&lt;li&gt;UTF-16 and varchar&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Also see &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://stackoverflow.com/questions/384974/trying-to-store-xml-content-into-sql-server-2005-fails-encoding-problem/385756#385756&quot;&gt;Trying to store XML content into SQL Server 2005 fails (encoding problem)&lt;/a&gt; whcih links to &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://social.msdn.microsoft.com/forums/en-US/sqlxml/thread/d40ef582-4ffe-4f4b-b6b8-03c6c0ba1a32/&quot;&gt;http://social.msdn.microsoft.com/forums/en-US/sqlxml/thread/d40ef582-4ffe-4f4b-b6b8-03c6c0ba1a32/&lt;/a&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt; 

</content><link rel='replies' type='application/atom+xml' href='https://supers-affiliate.blogspot.com/feeds/3645919077581800283/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/saving-xml-contents-with-iso-8859-1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/3645919077581800283'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7204472375574233207/posts/default/3645919077581800283'/><link rel='alternate' type='text/html' href='https://supers-affiliate.blogspot.com/2024/08/saving-xml-contents-with-iso-8859-1.html' title='Saving Xml Contents With Iso-8859-1 Encoding Using Entity Framework Into Sql Server 2008&#39;s Xml Column Gives Encoding Error'/><author><name>Blake Hickle</name><uri>http://www.blogger.com/profile/04290019036198769750</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>