<?xml version="1.0" encoding="utf-8"?><!-- generator="b2evolution/6.11.7-stable" -->
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>=tg= Thomas Grohser - Category: "Tips&#38;Tricks"</title>
		<link>https://www.insidesql.org/blogs/tgrohser/</link>
		<atom:link rel="self" type="application/rss+xml" href="https://www.insidesql.org/blogs/tgrohser/?tempskin=_rss2" />
		<description>InsideSQL.org Blogs - Blogs über SQL Server</description>
		<language>en-EU</language>
		<docs>http://blogs.law.harvard.edu/tech/rss</docs>
		<admin:generatorAgent rdf:resource="http://b2evolution.net/?v=6.11.7-stable"/>
		<ttl>60</ttl>
				<item>
			<title>Filtered Index with WHERE col IN (...) clause</title>
			<link>https://www.insidesql.org/blogs/tgrohser/2011/07/14/filtered-index-with-where-col</link>
			<pubDate>Thu, 14 Jul 2011 10:27:00 +0000</pubDate>			<dc:creator>=tg=</dc:creator>
			<category domain="main">Tips&amp;Tricks</category>			<guid isPermaLink="false">2987@https://www.insidesql.org/blogs/</guid>
						<description>I was asked if it is possible to create an filtered index with a WHERE col IN (…) clause and then use WHERE col = n   with n being one of the values of the (…) list

So let’s create a small sample

create table idx
(
      ID int NOT NULL IDENTITY(1,1) primary key clustered,
      Data int
)
insert into idx (Data) values (1)
go 100
insert into idx (Data) values (2)
go 2
insert into idx (Data) values (3)
go 2

create index idx1 on idx(ID)
where Data in (2,3)

select ID from idx where Data in (2, 3)         -- Index is used

select ID from idx where Data = 2               -- Table scan

select ID from idx where Data in (2, 3) AND Data = 2 -- Table scan

-- But that’s not because SQL is not smart we created the index wrong

drop index idx1 on idx

create index idx1 on idx(ID)
INCLUDE (Data)      -- if the data we filter on is not in the index SQL has to do a lookup on the table         
where Data in (2,3) -- and therefore chooses to make an full table scan

select ID from idx where Data in (2, 3)   -- Index is used

select ID from idx where Data = 2  -- Index is used  !!!!    THATS what we wanted

select ID from idx where Data = 1  -- Table scan as expected</description>
			<content:encoded><![CDATA[I was asked if it is possible to create an filtered index with a WHERE col IN (…) clause and then use WHERE col = n   with n being one of the values of the (…) list

So let’s create a small sample

create table idx
(
      ID int NOT NULL IDENTITY(1,1) primary key clustered,
      Data int
)
insert into idx (Data) values (1)
go 100
insert into idx (Data) values (2)
go 2
insert into idx (Data) values (3)
go 2

create index idx1 on idx(ID)
where Data in (2,3)

select ID from idx where Data in (2, 3)         -- Index is used

select ID from idx where Data = 2               -- Table scan

select ID from idx where Data in (2, 3) AND Data = 2 -- Table scan

-- But that’s not because SQL is not smart we created the index wrong

drop index idx1 on idx

create index idx1 on idx(ID)
INCLUDE (Data)      -- if the data we filter on is not in the index SQL has to do a lookup on the table         
where Data in (2,3) -- and therefore chooses to make an full table scan

select ID from idx where Data in (2, 3)   -- Index is used

select ID from idx where Data = 2  -- Index is used  !!!!    THATS what we wanted

select ID from idx where Data = 1  -- Table scan as expected]]></content:encoded>
								<comments>https://www.insidesql.org/blogs/tgrohser/2011/07/14/filtered-index-with-where-col#comments</comments>
			<wfw:commentRss>https://www.insidesql.org/blogs/tgrohser/?tempskin=_rss2&#38;disp=comments&#38;p=2987</wfw:commentRss>
		</item>
				<item>
			<title>Just deployed my first SQL Azure database.</title>
			<link>https://www.insidesql.org/blogs/tgrohser/2011/01/28/just-deployed-my-first-sql-azure-database</link>
			<pubDate>Fri, 28 Jan 2011 15:39:53 +0000</pubDate>			<dc:creator>=tg=</dc:creator>
			<category domain="main">Tips&amp;Tricks</category>			<guid isPermaLink="false">2535@https://www.insidesql.org/blogs/</guid>
						<description>&lt;p&gt;Quiet an adventure as with all IT related things: SQL Azure is &lt;em&gt;&lt;strong&gt;almost&lt;/strong&gt;&lt;/em&gt; like SQL Server. Emphasis on the almost. But after a little fighting I got it running. Time will tell us how well it is going to run.&lt;/p&gt;
&lt;p&gt;My tip to all is to have a deployment script that only contains what you realy need and not a generated ones that specifies each and every default option. Why: SQL Azure does not know many of the default options and therefore the script fails in that case.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;</description>
			<content:encoded><![CDATA[<p>Quiet an adventure as with all IT related things: SQL Azure is <em><strong>almost</strong></em> like SQL Server. Emphasis on the almost. But after a little fighting I got it running. Time will tell us how well it is going to run.</p>
<p>My tip to all is to have a deployment script that only contains what you realy need and not a generated ones that specifies each and every default option. Why: SQL Azure does not know many of the default options and therefore the script fails in that case.</p>
<p> </p>]]></content:encoded>
								<comments>https://www.insidesql.org/blogs/tgrohser/2011/01/28/just-deployed-my-first-sql-azure-database#comments</comments>
			<wfw:commentRss>https://www.insidesql.org/blogs/tgrohser/?tempskin=_rss2&#38;disp=comments&#38;p=2535</wfw:commentRss>
		</item>
				<item>
			<title>How to assign a text containing a single quote to a char, varchar, nchar or nvarchar valiable or colum</title>
			<link>https://www.insidesql.org/blogs/tgrohser/2011/01/27/how-to-assign-a-text-containing-a-single-quote-to-a-char-varchar-nchar-or-nvarchar-valiable-or-colum</link>
			<pubDate>Thu, 27 Jan 2011 12:12:00 +0000</pubDate>			<dc:creator>=tg=</dc:creator>
			<category domain="main">Tips&amp;Tricks</category>			<guid isPermaLink="false">2499@https://www.insidesql.org/blogs/</guid>
						<description>&lt;p&gt;&lt;span style=&quot;font-family: &#039;Calibri&#039;, &#039;sans-serif&#039;; font-size: 11pt;&quot;&gt;Sometimes the need to assign a text like &quot;She&#039;s the boss&quot; to a text column or variable arises.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;line-height: 115%; font-family: &#039;Courier New&#039;; color: blue; font-size: 10pt; mso-no-proof: yes;&quot;&gt;DECLARE&lt;/span&gt;&lt;span style=&quot;line-height: 115%; font-family: &#039;Courier New&#039;; font-size: 10pt; mso-no-proof: yes;&quot;&gt; @MyText &lt;span style=&quot;color: blue;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;NVARCHAR&lt;/span&gt;&lt;span style=&quot;color: gray;&quot;&gt;(&lt;/span&gt;100&lt;span style=&quot;color: gray;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: gray;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#039;She&#039;&lt;/span&gt;s the boss&lt;span style=&quot;color: red;&quot;&gt;&#039;;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-family: &#039;Calibri&#039;, &#039;sans-serif&#039;; font-size: 11pt;&quot;&gt;You can already see on the syntax coloring that something is wrong. To put a single quote inside a string literal you must precede it with another single quote&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-family: &#039;Courier New&#039;; color: blue; font-size: 10pt; mso-no-proof: yes;&quot;&gt;DECLARE&lt;/span&gt;&lt;span style=&quot;font-family: &#039;Courier New&#039;; font-size: 10pt; mso-no-proof: yes;&quot;&gt; @MyText &lt;span style=&quot;color: blue;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;NVARCHAR&lt;/span&gt;&lt;span style=&quot;color: gray;&quot;&gt;(&lt;/span&gt;100&lt;span style=&quot;color: gray;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: gray;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#039;She&#039;&#039;s the boss&#039;&lt;/span&gt;&lt;span style=&quot;color: gray;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-family: &#039;Calibri&#039;, &#039;sans-serif&#039;; font-size: 11pt;&quot;&gt; If you run the whole batch below &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-family: &#039;Courier New&#039;; color: blue; font-size: 10pt; mso-no-proof: yes;&quot;&gt;DECLARE&lt;/span&gt;&lt;span style=&quot;font-family: &#039;Courier New&#039;; font-size: 10pt; mso-no-proof: yes;&quot;&gt; @MyText &lt;span style=&quot;color: blue;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;NVARCHAR&lt;/span&gt;&lt;span style=&quot;color: gray;&quot;&gt;(&lt;/span&gt;100&lt;span style=&quot;color: gray;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: gray;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#039;She&#039;&#039;s the boss&#039;&lt;/span&gt;&lt;span style=&quot;color: gray;&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#039;Courier New&#039;; color: blue; font-size: 10pt; mso-no-proof: yes;&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;font-family: &#039;Courier New&#039;; font-size: 10pt; mso-no-proof: yes;&quot;&gt; @MyText&lt;span style=&quot;color: gray;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-family: &#039;Calibri&#039;, &#039;sans-serif&#039;; font-size: 11pt;&quot;&gt;You will see it produces the desired result:&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;  &lt;/span&gt;&lt;em&gt;She&#039;s the boss&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-family: &#039;Calibri&#039;, &#039;sans-serif&#039;; font-size: 11pt;&quot;&gt;To give you another example the text ‘I am between single quotes’ would look like this&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &#039;Courier New&#039;; color: blue; font-size: 10pt; mso-no-proof: yes;&quot;&gt;DECLARE&lt;/span&gt;&lt;span style=&quot;font-family: &#039;Courier New&#039;; font-size: 10pt; mso-no-proof: yes;&quot;&gt; @MyText &lt;span style=&quot;color: blue;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;NVARCHAR&lt;/span&gt;&lt;span style=&quot;color: gray;&quot;&gt;(&lt;/span&gt;100&lt;span style=&quot;color: gray;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: gray;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;&#039;&#039;&#039;I am between single quotes&#039;&#039;&#039;&lt;/span&gt;&lt;span style=&quot;color: gray;&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#039;Courier New&#039;; color: blue; font-size: 10pt; mso-no-proof: yes;&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;font-family: &#039;Courier New&#039;; font-size: 10pt; mso-no-proof: yes;&quot;&gt; @MyText&lt;span style=&quot;color: gray;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;</description>
			<content:encoded><![CDATA[<p><span style="font-family: 'Calibri', 'sans-serif'; font-size: 11pt;">Sometimes the need to assign a text like "She's the boss" to a text column or variable arises.</span></p>
<p class="MsoNormal"><span style="line-height: 115%; font-family: 'Courier New'; color: blue; font-size: 10pt; mso-no-proof: yes;">DECLARE</span><span style="line-height: 115%; font-family: 'Courier New'; font-size: 10pt; mso-no-proof: yes;"> @MyText <span style="color: blue;">AS</span> <span style="color: blue;">NVARCHAR</span><span style="color: gray;">(</span>100<span style="color: gray;">)</span> <span style="color: gray;">=</span> <span style="color: red;">'She'</span>s the boss<span style="color: red;">';</span></span></p>
<p><span style="font-family: 'Calibri', 'sans-serif'; font-size: 11pt;">You can already see on the syntax coloring that something is wrong. To put a single quote inside a string literal you must precede it with another single quote</span></p>
<p><span style="font-family: 'Courier New'; color: blue; font-size: 10pt; mso-no-proof: yes;">DECLARE</span><span style="font-family: 'Courier New'; font-size: 10pt; mso-no-proof: yes;"> @MyText <span style="color: blue;">AS</span> <span style="color: blue;">NVARCHAR</span><span style="color: gray;">(</span>100<span style="color: gray;">)</span> <span style="color: gray;">=</span> <span style="color: red;">'She''s the boss'</span><span style="color: gray;">;</span></span></p>
<p><span style="font-family: 'Calibri', 'sans-serif'; font-size: 11pt;"> If you run the whole batch below </span></p>
<p><span style="font-family: 'Courier New'; color: blue; font-size: 10pt; mso-no-proof: yes;">DECLARE</span><span style="font-family: 'Courier New'; font-size: 10pt; mso-no-proof: yes;"> @MyText <span style="color: blue;">AS</span> <span style="color: blue;">NVARCHAR</span><span style="color: gray;">(</span>100<span style="color: gray;">)</span> <span style="color: gray;">=</span> <span style="color: red;">'She''s the boss'</span><span style="color: gray;">;<br /></span></span><span style="font-family: 'Courier New'; color: blue; font-size: 10pt; mso-no-proof: yes;">SELECT</span><span style="font-family: 'Courier New'; font-size: 10pt; mso-no-proof: yes;"> @MyText<span style="color: gray;">;</span></span></p>
<p><span style="font-family: 'Calibri', 'sans-serif'; font-size: 11pt;">You will see it produces the desired result:<span style="mso-spacerun: yes;">  </span><em>She's the boss</em></span></p>
<p><span style="font-family: 'Calibri', 'sans-serif'; font-size: 11pt;">To give you another example the text ‘I am between single quotes’ would look like this</span></p>
<p class="MsoNormal"><span style="font-family: 'Courier New'; color: blue; font-size: 10pt; mso-no-proof: yes;">DECLARE</span><span style="font-family: 'Courier New'; font-size: 10pt; mso-no-proof: yes;"> @MyText <span style="color: blue;">AS</span> <span style="color: blue;">NVARCHAR</span><span style="color: gray;">(</span>100<span style="color: gray;">)</span> <span style="color: gray;">=</span> <span style="color: red;">'''I am between single quotes'''</span><span style="color: gray;">;<br /></span></span><span style="font-family: 'Courier New'; color: blue; font-size: 10pt; mso-no-proof: yes;">SELECT</span><span style="font-family: 'Courier New'; font-size: 10pt; mso-no-proof: yes;"> @MyText<span style="color: gray;">;</span></span></p>]]></content:encoded>
								<comments>https://www.insidesql.org/blogs/tgrohser/2011/01/27/how-to-assign-a-text-containing-a-single-quote-to-a-char-varchar-nchar-or-nvarchar-valiable-or-colum#comments</comments>
			<wfw:commentRss>https://www.insidesql.org/blogs/tgrohser/?tempskin=_rss2&#38;disp=comments&#38;p=2499</wfw:commentRss>
		</item>
			</channel>
</rss>
