<?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>Diverse</title><link>http://sqlserver.ro/forums/27/ShowForum.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Re: Comportament varchar/char</title><link>http://sqlserver.ro/forums/thread/1494.aspx</link><pubDate>Tue, 09 Jan 2007 07:32:43 GMT</pubDate><guid isPermaLink="false">963f3a18-65dd-4aad-905c-b785cfe1d7c7:1494</guid><dc:creator>rsocol</dc:creator><slash:comments>0</slash:comments><comments>http://sqlserver.ro/forums/thread/1494.aspx</comments><wfw:commentRss>http://sqlserver.ro/forums/commentrss.aspx?SectionID=27&amp;PostID=1494</wfw:commentRss><description>&lt;p&gt;Comportamentul SQL Server la compararea unor expresii de tip caracter este documentat la&lt;font size="-1"&gt;: &lt;a href="http://msdn2.microsoft.com/en-us/ms189863.aspx" target="_blank"&gt;http://&lt;span class="a"&gt;msdn2.microsoft.com/en-us/ms189863.aspx&lt;/span&gt;&lt;/a&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;În această pagină se face referire şi la standardul SQL-92. Un draft aproape final al acestui standard e disponibil la adresa: &lt;a href="http://www.contrib.andrew.cmu.edu/%7Eshadow/sql/sql1992.txt"&gt;http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt&lt;/a&gt; (standardul oficial e disponibil contra cost de la ISO sau ANSI).&lt;/p&gt;&lt;p&gt;După câte înţeleg eu, situaţia e puţin invers: nu se scot spaţiile, ci se adaugă. Vezi punctul 3) din secţiunea 8.2 &amp;lt;comparison predicate&amp;gt; a standardului:&lt;/p&gt;&lt;pre&gt;            The comparison of two character strings is determined as follows:&lt;br&gt;&lt;br&gt;            a) If the length in characters of X is not equal to the length&lt;br&gt;              in characters of Y, then the shorter string is effectively&lt;br&gt;              replaced, for the purposes of comparison, with a copy of&lt;br&gt;              itself that has been extended to the length of the longer&lt;br&gt;              string by concatenation on the right of one or more pad char-&lt;br&gt;              acters, where the pad character is chosen based on CS. If&lt;br&gt;              CS has the NO PAD attribute, then the pad character is an&lt;br&gt;              implementation-dependent character different from any char-&lt;br&gt;              acter in the character set of X and Y that collates less&lt;br&gt;              than any string under CS. Otherwise, the pad character is a&lt;br&gt;              &amp;lt;space&amp;gt;.&lt;br&gt;&lt;br&gt;            b) The result of the comparison of X and Y is given by the col-&lt;br&gt;              lating sequence CS.&lt;br&gt;&lt;br&gt;            c) Depending on the collating sequence, two strings may com-&lt;br&gt;              pare as equal even if they are of different lengths or con-&lt;br&gt;              tain different sequences of characters. When the operations&lt;br&gt;              MAX, MIN, DISTINCT, references to a grouping column, and the&lt;br&gt;              UNION, EXCEPT, and INTERSECT operators refer to character&lt;br&gt;              strings, the specific value selected by these operations from&lt;br&gt;              a set of such equal values is implementation-dependent.&lt;/pre&gt;&lt;p&gt;Răzvan&lt;br&gt;&lt;/p&gt;</description></item><item><title>Comportament varchar/char</title><link>http://sqlserver.ro/forums/thread/1493.aspx</link><pubDate>Tue, 09 Jan 2007 06:35:49 GMT</pubDate><guid isPermaLink="false">963f3a18-65dd-4aad-905c-b785cfe1d7c7:1493</guid><dc:creator>lmsasu</dc:creator><slash:comments>0</slash:comments><comments>http://sqlserver.ro/forums/thread/1493.aspx</comments><wfw:commentRss>http://sqlserver.ro/forums/commentrss.aspx?SectionID=27&amp;PostID=1493</wfw:commentRss><description>&lt;p&gt;Salut, &lt;/p&gt;&lt;p&gt;am o tabela creata astfel:&lt;/p&gt;&lt;p&gt;&amp;nbsp;CREATE TABLE [dbo].[Test](&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;[id] [int] IDENTITY(1,1) NOT NULL,&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;[nume] [nchar](10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;[prenume] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,&lt;br&gt;&amp;nbsp;CONSTRAINT [PK_Test] PRIMARY KEY CLUSTERED &lt;br&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;[id] ASC&lt;br&gt;)WITH (PAD_INDEX&amp;nbsp; = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]&lt;br&gt;) ON [PRIMARY]&lt;br&gt;&lt;/p&gt;&lt;p&gt;Inserez in tabela:&lt;/p&gt;&lt;p&gt;insert into Test (nume, prenume) values ('Popescu', 'Ana')&lt;/p&gt;&lt;p&gt;Caut:&lt;/p&gt;&lt;p&gt;select nume, prenume from test where nume='Popescu '&lt;br&gt;select nume, prenume from test where prenume='Ana '&lt;/p&gt;&lt;p&gt;Remarcati spatiul de la sfarsitul stringurilor, inainte de apostroful de inchidere. &lt;/p&gt;&lt;p&gt;Rezultat: de fiecare data imi returneaza inregistrarea inserata, chiar daca valorile puse intial sunt fara spatii la sfarsit; treaba se intampla atat pentru nchar cat si pentru nvarchar. De ce? Operatorul egal face cumva si trimming, automat? Care e explicatia? S-ar putea sa fie si un raspuns de tipul RTFM, dar dati o referinta :)&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;br&gt;Lucian&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item></channel></rss>