<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlserver.ro/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Intrebari generale</title><link>http://sqlserver.ro/forums/16/ShowForum.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Re: Intrebare de pe ITboard - Refactor Cursor to SELECT</title><link>http://sqlserver.ro/forums/thread/461.aspx</link><pubDate>Sat, 21 Oct 2006 07:48:40 GMT</pubDate><guid isPermaLink="false">963f3a18-65dd-4aad-905c-b785cfe1d7c7:461</guid><dc:creator>xmldeveloper</dc:creator><slash:comments>0</slash:comments><comments>http://sqlserver.ro/forums/thread/461.aspx</comments><wfw:commentRss>http://sqlserver.ro/forums/commentrss.aspx?SectionID=16&amp;PostID=461</wfw:commentRss><description>&lt;p&gt;Rulati urmatorul cod si includeti planul de executie (varianta cursor e clar mai neperformanta):&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;USE tempdb&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;GO&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;CREATE TABLE MyTable (ID INT PRIMARY KEY, VAL VARCHAR(64))&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;GO&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;DECLARE @I INT&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;SET @I = 1&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;WHILE @I &amp;lt; 100&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;BEGIN&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;INSERT INTO MyTable (ID,VAL) VALUES (@I, &amp;#39;VAL:&amp;#39;+CAST(@I AS VARCHAR(4)));&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;SET @I=@I+1&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;END&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;GO &lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&amp;nbsp;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;-- Varianta SELECT&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;DECLARE @Lista VARCHAR(MAX)&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;SET @Lista = &amp;#39;&amp;#39;;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;SELECT @Lista=@Lista + VAL + &amp;#39; &amp;#39; FROM MyTable&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;GO&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;-- Varianta CURSOR&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;DECLARE @Lista VARCHAR(MAX)&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;DECLARE @Valoare VARCHAR(32);&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;SET @Lista = &amp;#39;&amp;#39;;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&amp;nbsp;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;DECLARE ListaCursor CURSOR &lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;FOR SELECT VAL FROM MyTable&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;OPEN ListaCursor&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;FETCH NEXT FROM ListaCursor INTO @Valoare&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;WHILE @@FETCH_STATUS = 0&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;BEGIN&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;SET @Lista = @Lista + @Valoare + &amp;#39; &amp;#39;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;FETCH NEXT FROM ListaCursor INTO @Valoare&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;END&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;CLOSE ListaCursor&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;DEALLOCATE ListaCursor&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;GO&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&amp;nbsp;&lt;/span&gt;&lt;/strong&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&amp;nbsp;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;"&gt;&lt;font face="Times New Roman"&gt;&amp;nbsp;&lt;/font&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Intrebare de pe ITboard - Refactor Cursor to SELECT</title><link>http://sqlserver.ro/forums/thread/460.aspx</link><pubDate>Sat, 21 Oct 2006 07:28:01 GMT</pubDate><guid isPermaLink="false">963f3a18-65dd-4aad-905c-b785cfe1d7c7:460</guid><dc:creator>xmldeveloper</dc:creator><slash:comments>0</slash:comments><comments>http://sqlserver.ro/forums/thread/460.aspx</comments><wfw:commentRss>http://sqlserver.ro/forums/commentrss.aspx?SectionID=16&amp;PostID=460</wfw:commentRss><description>&lt;p&gt;SELECT-ul va face un table scan (toate randurile tabelei sunt scanate).&lt;/p&gt;&lt;p&gt;Cursor-ul face acelasi lucru insa secvential si folosind mai multe resurse.&lt;/p&gt;</description></item><item><title>Re: Intrebare de pe ITboard - Refactor Cursor to SELECT</title><link>http://sqlserver.ro/forums/thread/459.aspx</link><pubDate>Fri, 20 Oct 2006 21:15:28 GMT</pubDate><guid isPermaLink="false">963f3a18-65dd-4aad-905c-b785cfe1d7c7:459</guid><dc:creator>marcel soare</dc:creator><slash:comments>0</slash:comments><comments>http://sqlserver.ro/forums/thread/459.aspx</comments><wfw:commentRss>http://sqlserver.ro/forums/commentrss.aspx?SectionID=16&amp;PostID=459</wfw:commentRss><description>&lt;p&gt;foarte interesant raspunsul tau.&lt;/p&gt;&lt;p&gt;intrebarea: performanta serverului este afectata, daca selectul se face pe un numar mare de inregistrari?&lt;/p&gt;&lt;p&gt;multumesc anticipat......&lt;img src="http://sqlserver.ro/emoticons/emotion-21.gif" alt="Yes" /&gt;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Intrebare de pe ITboard - Refactor Cursor to SELECT</title><link>http://sqlserver.ro/forums/thread/299.aspx</link><pubDate>Tue, 10 Oct 2006 10:24:17 GMT</pubDate><guid isPermaLink="false">963f3a18-65dd-4aad-905c-b785cfe1d7c7:299</guid><dc:creator>crestinul</dc:creator><slash:comments>0</slash:comments><comments>http://sqlserver.ro/forums/thread/299.aspx</comments><wfw:commentRss>http://sqlserver.ro/forums/commentrss.aspx?SectionID=16&amp;PostID=299</wfw:commentRss><description>multumesc</description></item><item><title>Re: Intrebare de pe ITboard - Refactor Cursor to SELECT</title><link>http://sqlserver.ro/forums/thread/298.aspx</link><pubDate>Tue, 10 Oct 2006 10:19:28 GMT</pubDate><guid isPermaLink="false">963f3a18-65dd-4aad-905c-b785cfe1d7c7:298</guid><dc:creator>xmldeveloper</dc:creator><slash:comments>0</slash:comments><comments>http://sqlserver.ro/forums/thread/298.aspx</comments><wfw:commentRss>http://sqlserver.ro/forums/commentrss.aspx?SectionID=16&amp;PostID=298</wfw:commentRss><description>&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;DECLARE @MyTable TABLE (ID INT PRIMARY KEY, VAL VARCHAR(64))&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&amp;nbsp;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;INSERT INTO @MyTable VALUES (1, &amp;#39;Cristian&amp;#39;)&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;INSERT INTO @MyTable VALUES (2, &amp;#39;Sorin&amp;#39;)&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;INSERT INTO @MyTable VALUES (3, &amp;#39;Narcis&amp;#39;)&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&amp;nbsp;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;DECLARE @Lista VARCHAR(MAX)&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;SET @Lista = &amp;#39;&amp;#39;;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&amp;nbsp;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;SELECT @Lista=@Lista + VAL + &amp;#39; &amp;#39; FROM @MyTable&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&amp;nbsp;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;SELECT RTRIM(@Lista) AS Lista&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;GO&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&amp;nbsp;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;-- Output&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;Lista&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;Cristian Sorin Narcis&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;</description></item><item><title>Intrebare de pe ITboard - Refactor Cursor to SELECT</title><link>http://sqlserver.ro/forums/thread/297.aspx</link><pubDate>Tue, 10 Oct 2006 10:17:55 GMT</pubDate><guid isPermaLink="false">963f3a18-65dd-4aad-905c-b785cfe1d7c7:297</guid><dc:creator>xmldeveloper</dc:creator><slash:comments>0</slash:comments><comments>http://sqlserver.ro/forums/thread/297.aspx</comments><wfw:commentRss>http://sqlserver.ro/forums/commentrss.aspx?SectionID=16&amp;PostID=297</wfw:commentRss><description>&lt;p&gt;&lt;strong&gt;geto_dacul wrote the following post:&lt;/strong&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;/p&gt;&lt;p&gt;Un amic de a meu a fost la un interviu si i s-a cerut sa faca un select care sa returneze intr-un camp agregat toate valorile unei coloane de tip text concatenate.&lt;/p&gt;&lt;p&gt;De ex coloana e nume de tip text(char,varchar) iar in selectul rezultat trebuie sa am in campul de iesire toate valorile coloanei comcatenate de ex gigle,ionel,....georgel.&lt;/p&gt;&lt;p&gt;Chestia asta se face simplu cu un cursur dar ei vor cu select&lt;/p&gt;&lt;p&gt;Intrebare mea exista vreo functie sql agregata care face chestia asta?&lt;/p&gt;&lt;p&gt;Multumesc &lt;br /&gt;&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/p&gt;</description></item></channel></rss>