<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" version="2.0">
  <channel>
    <title>SQL Joint - T-SQL</title>
    <link>http://www.sqljoint.com/</link>
    <description>Den digitale SQL hukommelse</description>
    <language>en-us</language>
    <copyright>Sune Hansen</copyright>
    <lastBuildDate>Fri, 25 Nov 2005 14:55:44 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>sdh@vertica.dk</managingEditor>
    <webMaster>sdh@vertica.dk</webMaster>
    <item>
      <trackback:ping>http://www.sqljoint.com/Trackback.aspx?guid=719e3aee-f2bb-4d1a-ad87-8885983bf34c</trackback:ping>
      <pingback:server>http://www.sqljoint.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.sqljoint.com/PermaLink,guid,719e3aee-f2bb-4d1a-ad87-8885983bf34c.aspx</pingback:target>
      <dc:creator>Sune Hansen</dc:creator>
      <wfw:comment>http://www.sqljoint.com/CommentView,guid,719e3aee-f2bb-4d1a-ad87-8885983bf34c.aspx</wfw:comment>
      <wfw:commentRss>http://www.sqljoint.com/SyndicationService.asmx/GetEntryCommentsRss?guid=719e3aee-f2bb-4d1a-ad87-8885983bf34c</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Det er ikke de helt vildt streng funktioner, der findes i T-SQL (okay, måske bliver
jeg klogere, når jeg får sat mig mere ind i T-SQL udvidelserne i SQL Server 2005,
men i hvert fald ikke i SQL Server 2000). Men selv med de simple funktioner kan man
lave nogle små fikse ting, hvis det bliver sat rigtigt sammen. I det følgende skal
vi finde ud af, hvor mange gange et bestemt ord findes i en kolonne. 
</p>
        <p>
Vi har følgende table:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">CREATE</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">TABLE</span> tbl_Demo
(<br />
    DemoID <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">INT</span>,<br />
    Description <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">VARCHAR</span>(8000)<br />
)    </span>
        </p>
        <p>
I den tabel vil vi finde ud af hvor mange gange order "server" i hver rækkes Description
felt. Det kan gøres på følgende måde:
</p>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <p>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> Description,
(<span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">LEN</span>(Description)
- <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">LEN</span>(<span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">REPLACE</span>(Description, <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'server'</span>, <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">''</span>)))
/ <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">LEN</span>(<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'server'</span>) <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AS</span> WordCount<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> tbl_Demo</span>
          </p>
        </span>
        <p>
Vi tager kort fortalt længden af Description feltet inkl. alle gange order "server"
måtte optræde, og trækker længden af Description feltet uden ordet "server" fra. For
at finde antallet af gang ’server’ indgår dividerer vi dette tal med længden af "server".
</p>
        <p>
Ved også at bruge udtrykket i en Order By kan vores statement tilmed bruges som en
søgefunktion, der sortere de mest relevante resultater øverst:
</p>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <p>
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> Description,
(<span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">LEN</span>(Description)
- <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">LEN</span>(<span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">REPLACE</span>(Description, <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'server'</span>, <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">''</span>)))
/ <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">LEN</span>(<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'server'</span>) <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AS</span> WordCount<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> tbl_Demo<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">ORDER</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BY</span> WordCount <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">DESC</span></span>
            </p>
          </span>
        </span>
        <p>
Måske ikke lige frem optimalt hvad angår performance, men trods alt en prioriteret
søgning.
</p>
        <img width="0" height="0" src="http://www.sqljoint.com/aggbug.ashx?id=719e3aee-f2bb-4d1a-ad87-8885983bf34c" />
      </body>
      <title>Antal gange et ord findes i en kolonne</title>
      <guid isPermaLink="false">http://www.sqljoint.com/PermaLink,guid,719e3aee-f2bb-4d1a-ad87-8885983bf34c.aspx</guid>
      <link>http://www.sqljoint.com/Antal+Gange+Et+Ord+Findes+I+En+Kolonne.aspx</link>
      <pubDate>Fri, 25 Nov 2005 14:55:44 GMT</pubDate>
      <description>&lt;p&gt;
Det er ikke de helt vildt streng funktioner, der findes i T-SQL (okay, måske bliver
jeg klogere, når jeg får sat mig mere ind i T-SQL udvidelserne i SQL Server 2005,
men i hvert fald ikke i SQL Server 2000). Men selv med de simple funktioner kan man
lave nogle små fikse ting, hvis det bliver sat rigtigt sammen. I det følgende skal
vi finde ud af, hvor mange gange et bestemt ord findes i en kolonne. 
&lt;/p&gt;
&lt;p&gt;
Vi har følgende table:
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;CREATE&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;TABLE&lt;/span&gt; tbl_Demo
(&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DemoID &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;INT&lt;/span&gt;,&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Description &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;VARCHAR&lt;/span&gt;(8000)&lt;br&gt;
)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
I den tabel vil vi finde ud af hvor mange gange order "server" i hver rækkes Description
felt. Det kan gøres på følgende måde:
&lt;/p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; Description,
(&lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;LEN&lt;/span&gt;(Description)
- &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;LEN&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;REPLACE&lt;/span&gt;(Description, &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'server'&lt;/span&gt;, &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;''&lt;/span&gt;)))
/ &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;LEN&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'server'&lt;/span&gt;) &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AS&lt;/span&gt; WordCount&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; tbl_Demo&lt;/span&gt;
&lt;/p&gt;
&lt;/span&gt; 
&lt;p&gt;
Vi tager kort fortalt længden af Description feltet inkl. alle gange order "server"
måtte optræde, og trækker længden af Description feltet uden ordet "server" fra. For
at finde antallet af gang ’server’ indgår dividerer vi dette tal med længden af "server".
&lt;/p&gt;
&lt;p&gt;
Ved også at bruge udtrykket i en Order By kan vores statement tilmed bruges som en
søgefunktion, der sortere de mest relevante resultater øverst:
&lt;/p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; Description,
(&lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;LEN&lt;/span&gt;(Description)
- &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;LEN&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;REPLACE&lt;/span&gt;(Description, &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'server'&lt;/span&gt;, &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;''&lt;/span&gt;)))
/ &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;LEN&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'server'&lt;/span&gt;) &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AS&lt;/span&gt; WordCount&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; tbl_Demo&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;ORDER&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BY&lt;/span&gt; WordCount &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;DESC&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/span&gt;&lt;/span&gt; 
&lt;p&gt;
Måske ikke lige frem optimalt hvad angår performance, men trods alt en prioriteret
søgning.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.sqljoint.com/aggbug.ashx?id=719e3aee-f2bb-4d1a-ad87-8885983bf34c" /&gt;</description>
      <comments>http://www.sqljoint.com/CommentView,guid,719e3aee-f2bb-4d1a-ad87-8885983bf34c.aspx</comments>
      <category>T-SQL</category>
    </item>
    <item>
      <trackback:ping>http://www.sqljoint.com/Trackback.aspx?guid=84757242-b574-4b86-9397-d5059e77f03b</trackback:ping>
      <pingback:server>http://www.sqljoint.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.sqljoint.com/PermaLink,guid,84757242-b574-4b86-9397-d5059e77f03b.aspx</pingback:target>
      <dc:creator>Sune Hansen</dc:creator>
      <wfw:comment>http://www.sqljoint.com/CommentView,guid,84757242-b574-4b86-9397-d5059e77f03b.aspx</wfw:comment>
      <wfw:commentRss>http://www.sqljoint.com/SyndicationService.asmx/GetEntryCommentsRss?guid=84757242-b574-4b86-9397-d5059e77f03b</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Default collation på SQL Server er case-insensitive. Det er som oftest også det
smarteste, så man ikke behøver koncentrere sig om at skrive f.eks. object navne med
den rigtige case. Ind imellem kunne det dog være rart, hvis man kunne lave en case-sensitive
WHERE-clause, f.eks. i forbindelse med, at en bruger angiver password til login.
</p>
        <p>
Eks:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> * <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> tbl_User <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> Password
= <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'superfly'</span></span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            </span>
          </span>Denne
returnerer både dem der har password: superfly, Superfly, SUPERFLY og lign., hvilket
ikke er hensigtsmæssigt.<br />
 <br />
Følgende lille trick giver til gengæld det ønskede resultat:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> * <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> tbl_User <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">CONVERT</span>(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BINARY</span>,
Password) = <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">CONVERT</span>(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BINARY</span>, <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'superfly'</span>)</span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          </span>Nu
vil kun brugere med password superfly blive returneret. Den binære værdi for f.eks.
s og S er forskellig, så nu risikerer vi ikke at få uønskede rækker returneret.
</p>
        <p>
Den betænksomme SQL programmør vil nu gøre opmærksom på, at et evt. index på kolonnen
Password ikke længere vil kunne anvendes, men at der vil skulle en table-scan til
for at finde den ønskede brugere.
</p>
        <p>
Dette kan man komme ud over med denne færdig SELECT:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> *
FORM tbl_User <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> Password
= <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'superfly'</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AND</span><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">CONVERT</span>(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BINARY</span>,
Password) = <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">CONVERT</span>(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BINARY</span>, <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'superfly'</span>)</span>
        </p>
        <p>
Et index kan nu anvendes til at finde de brugere, der har password superfly i en elle
anden form, og til sidst fjernes de brugere, der så ikke har det på den rigtige form
(den rigtige case).
</p>
        <p>
Vores mål er nu nået og vi har lavet en case-sensitive WHERE-clause på en database
med case-insensitive collation.<br /></p>
        <img width="0" height="0" src="http://www.sqljoint.com/aggbug.ashx?id=84757242-b574-4b86-9397-d5059e77f03b" />
      </body>
      <title>Case-sensitive WHERE clause ved case-insensitive collation</title>
      <guid isPermaLink="false">http://www.sqljoint.com/PermaLink,guid,84757242-b574-4b86-9397-d5059e77f03b.aspx</guid>
      <link>http://www.sqljoint.com/Casesensitive+WHERE+Clause+Ved+Caseinsensitive+Collation.aspx</link>
      <pubDate>Sun, 30 Oct 2005 20:14:13 GMT</pubDate>
      <description>&lt;p&gt;
Default collation på SQL Server er&amp;nbsp;case-insensitive. Det er som oftest også det
smarteste, så man ikke behøver koncentrere sig om at skrive f.eks. object navne med
den rigtige case. Ind imellem kunne det dog være rart, hvis man kunne lave en case-sensitive
WHERE-clause, f.eks. i forbindelse med, at en bruger angiver password til login.
&lt;/p&gt;
&lt;p&gt;
Eks:
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; * &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; tbl_User &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; Password
= &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'superfly'&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;/span&gt;&lt;/span&gt;Denne
returnerer både dem der har password: superfly, Superfly, SUPERFLY og lign., hvilket
ikke er hensigtsmæssigt.&lt;br&gt;
&amp;nbsp;&lt;br&gt;
Følgende lille trick giver til gengæld det ønskede resultat:
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; * &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; tbl_User &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;CONVERT&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BINARY&lt;/span&gt;,
Password) = &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;CONVERT&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BINARY&lt;/span&gt;, &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'superfly'&lt;/span&gt;)&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;/span&gt;Nu
vil kun brugere med password superfly blive returneret. Den binære værdi for f.eks.
s og S er forskellig, så nu risikerer vi ikke at få uønskede rækker returneret.
&lt;/p&gt;
&lt;p&gt;
Den betænksomme SQL programmør vil nu gøre opmærksom på, at et evt. index på kolonnen
Password ikke længere vil kunne anvendes, men at der vil skulle en table-scan til
for at finde den ønskede brugere.
&lt;/p&gt;
&lt;p&gt;
Dette kan man komme ud over med denne færdig SELECT:
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; *
FORM tbl_User &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; Password
= &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'superfly'&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AND&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;CONVERT&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BINARY&lt;/span&gt;,
Password) = &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;CONVERT&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BINARY&lt;/span&gt;, &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'superfly'&lt;/span&gt;)&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
Et index kan nu anvendes til at finde de brugere, der har password superfly i en elle
anden form, og til sidst fjernes de brugere, der så ikke har det på den rigtige form
(den rigtige case).
&lt;/p&gt;
&lt;p&gt;
Vores mål er nu nået og vi har lavet en case-sensitive WHERE-clause på en database
med case-insensitive collation.&lt;br&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.sqljoint.com/aggbug.ashx?id=84757242-b574-4b86-9397-d5059e77f03b" /&gt;</description>
      <comments>http://www.sqljoint.com/CommentView,guid,84757242-b574-4b86-9397-d5059e77f03b.aspx</comments>
      <category>T-SQL</category>
    </item>
    <item>
      <trackback:ping>http://www.sqljoint.com/Trackback.aspx?guid=111ca509-c2e1-44b7-80d0-3c2de021f73d</trackback:ping>
      <pingback:server>http://www.sqljoint.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.sqljoint.com/PermaLink,guid,111ca509-c2e1-44b7-80d0-3c2de021f73d.aspx</pingback:target>
      <dc:creator>Sune Hansen</dc:creator>
      <wfw:comment>http://www.sqljoint.com/CommentView,guid,111ca509-c2e1-44b7-80d0-3c2de021f73d.aspx</wfw:comment>
      <wfw:commentRss>http://www.sqljoint.com/SyndicationService.asmx/GetEntryCommentsRss?guid=111ca509-c2e1-44b7-80d0-3c2de021f73d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Som nævnt tidligere er denne blog også lidt at betragte som min digitale hukommelse.
Efterhånden er jeg ved at have fundet disse SQL statements så mange gange i mine andre
arkiver, at de er ved at hænge ved. Men måske der er andre, der ikke har så meget
orden i papirarkiverne som jeg(!?!), og som finde det lettere at slå op på nettet.
Her kommer 3 metoder til at slette dubletter i en tabel:
</p>
        <p>
Vi vil gå ud fra en tabel med personer, som har følgende definition:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">CREATE</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">TABLE</span> tbl_Person
(<br />
Id <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">INT</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IDENTITY</span>(1,
1),<br />
FirstName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">VARCHAR</span>(50),<br />
LastName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">VARCHAR</span>(50)<br />
)</span>
        </p>
        <p>
og målet er at slette dubletter af kombinationen FirstName og LastName.
</p>
        <p>
Metode 1:<br /><span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">DELETE</span> tbl_Person<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> tbl_Person <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AS</span> P1<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">EXISTS</span> (<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> 1 <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> tbl_Person <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AS</span> P2 <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> P2.Id
&gt; P1.Id <span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">and</span> P1.FirstName
= P2.FirstName <span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">and</span> P1.LastName
= P2.LastName)</span></p>
        <p>
Skeler man til performance er denne metode noget af det mest effektive man kan komme
op med.
</p>
        <p>
Metode 2:<br /><span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">DELETE</span> P1<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> tbl_Person <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AS</span> P1<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">INNER</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">JOIN</span> tbl_Person <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AS</span> P2 <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">ON</span> P1.FirstName
= P2.FirstName <span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AND</span> P1.LastName
= P2.LastName <span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AND</span> P1.Id
&gt; P2.Id</span></p>
        <p>
Og endelig metode 3:<br /><span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">DELETE</span> tbl_Person<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> tbl_Person <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AS</span> P1<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> Id
&gt; (<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">MIN</span>(Id)<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> tbl_Person <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AS</span> P2<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> P1.FirstName
= P2.FirstName<br /><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AND</span> P1.LastName
= P2.LastName)</span></p>
        <p>
Alle tre metoder gør det samme, nemlig sletter dubletter. Som altid når man sletter
flere rækker er det en god idé at SELECT’e rækkerne ud før man sletter dem, så man
sikrer at det ser rigtigt ud.
</p>
        <img width="0" height="0" src="http://www.sqljoint.com/aggbug.ashx?id=111ca509-c2e1-44b7-80d0-3c2de021f73d" />
      </body>
      <title>En klassiker - slet dubletter i en tabel</title>
      <guid isPermaLink="false">http://www.sqljoint.com/PermaLink,guid,111ca509-c2e1-44b7-80d0-3c2de021f73d.aspx</guid>
      <link>http://www.sqljoint.com/En+Klassiker+Slet+Dubletter+I+En+Tabel.aspx</link>
      <pubDate>Wed, 26 Oct 2005 14:25:13 GMT</pubDate>
      <description>&lt;p&gt;
Som nævnt tidligere er denne blog også lidt at betragte som min digitale hukommelse.
Efterhånden er jeg ved at have fundet disse SQL statements så mange gange i mine andre
arkiver, at de er ved at hænge ved. Men måske der er andre, der ikke har så meget
orden i papirarkiverne som jeg(!?!), og som finde det lettere at slå op på nettet.
Her kommer 3 metoder til at slette dubletter i en tabel:
&lt;/p&gt;
&lt;p&gt;
Vi vil gå ud fra en tabel med personer, som har følgende definition:
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;CREATE&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;TABLE&lt;/span&gt; tbl_Person
(&lt;br&gt;
Id &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;INT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IDENTITY&lt;/span&gt;(1,
1),&lt;br&gt;
FirstName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;VARCHAR&lt;/span&gt;(50),&lt;br&gt;
LastName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;VARCHAR&lt;/span&gt;(50)&lt;br&gt;
)&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
og målet er at slette dubletter af kombinationen FirstName og LastName.
&lt;/p&gt;
&lt;p&gt;
Metode 1:&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;DELETE&lt;/span&gt; tbl_Person&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; tbl_Person &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AS&lt;/span&gt; P1&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;EXISTS&lt;/span&gt; (&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; 1 &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; tbl_Person &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AS&lt;/span&gt; P2 &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; P2.Id
&amp;gt; P1.Id &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;and&lt;/span&gt; P1.FirstName
= P2.FirstName &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;and&lt;/span&gt; P1.LastName
= P2.LastName)&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
Skeler man til performance er denne metode noget af det mest effektive man kan komme
op med.
&lt;/p&gt;
&lt;p&gt;
Metode 2:&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;DELETE&lt;/span&gt; P1&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; tbl_Person &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AS&lt;/span&gt; P1&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;INNER&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;JOIN&lt;/span&gt; tbl_Person &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AS&lt;/span&gt; P2 &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;ON&lt;/span&gt; P1.FirstName
= P2.FirstName &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AND&lt;/span&gt; P1.LastName
= P2.LastName &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AND&lt;/span&gt; P1.Id
&amp;gt; P2.Id&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
Og endelig metode 3:&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;DELETE&lt;/span&gt; tbl_Person&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; tbl_Person &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AS&lt;/span&gt; P1&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; Id
&amp;gt; (&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;MIN&lt;/span&gt;(Id)&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; tbl_Person &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AS&lt;/span&gt; P2&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; P1.FirstName
= P2.FirstName&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AND&lt;/span&gt; P1.LastName
= P2.LastName)&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
Alle tre metoder gør det samme, nemlig sletter dubletter. Som altid når man sletter
flere rækker er det en god idé at SELECT’e rækkerne ud før man sletter dem, så man
sikrer at det ser rigtigt ud.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.sqljoint.com/aggbug.ashx?id=111ca509-c2e1-44b7-80d0-3c2de021f73d" /&gt;</description>
      <comments>http://www.sqljoint.com/CommentView,guid,111ca509-c2e1-44b7-80d0-3c2de021f73d.aspx</comments>
      <category>T-SQL</category>
    </item>
  </channel>
</rss>