<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>FlexiCoder Blog &#187; query syntax</title>
	<atom:link href="http://www.flexicoder.com/blog/index.php/tag/query-syntax/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.flexicoder.com/blog</link>
	<description></description>
	<lastBuildDate>Wed, 28 Jul 2010 15:11:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SQL Server 2008 &#8211; Table Valued Parameters</title>
		<link>http://www.flexicoder.com/blog/index.php/2010/06/sql-server-2008-table-valued-parameters/</link>
		<comments>http://www.flexicoder.com/blog/index.php/2010/06/sql-server-2008-table-valued-parameters/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 19:39:54 +0000</pubDate>
		<dc:creator>flexicoder</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[.Net security]]></category>
		<category><![CDATA[query syntax]]></category>

		<guid isPermaLink="false">http://www.flexicoder.com/blog/?p=329</guid>
		<description><![CDATA[Here is a great article that explains how to use TVP&#8217;s via .Net and a stored procedure
Social Bookmarking]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.sommarskog.se/arrays-in-sql-2008.html">Here</a> is a great article that explains how to use TVP&#8217;s via .Net and a stored procedure</p>
<br/><a href="http://www.socialmarker.com/?link=http://www.flexicoder.com/blog/index.php/2010/06/sql-server-2008-table-valued-parameters/&title=SQL+Server+2008+%26%238211%3B+Table+Valued+Parameters&text=Here+is+a+great+article+that+explains+how+to+use+TVP%26%238217%3Bs+via+.Net+and+a+stored+procedure...&tags=" target="_blank"><img src= "http://www.socialmarker.com/bookmark.gif" border="0" /></a><noscript><a href="http://www.socialmarker.com" >Social Bookmarking</a></noscript>]]></content:encoded>
			<wfw:commentRss>http://www.flexicoder.com/blog/index.php/2010/06/sql-server-2008-table-valued-parameters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Grant Execute for Stored Procs</title>
		<link>http://www.flexicoder.com/blog/index.php/2010/04/sql-grant-execute-for-stored-procs/</link>
		<comments>http://www.flexicoder.com/blog/index.php/2010/04/sql-grant-execute-for-stored-procs/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 19:58:34 +0000</pubDate>
		<dc:creator>flexicoder</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[query syntax]]></category>

		<guid isPermaLink="false">http://www.flexicoder.com/blog/?p=308</guid>
		<description><![CDATA[Found this great article that has a really simple script to create the grant commands needed for all the procs in a database
Social Bookmarking]]></description>
			<content:encoded><![CDATA[<p>Found this great <a href="http://yellowduckguy.spaces.live.com/Blog/cns!DA380C13569E8907!166.entry">article</a> that has a really simple script to create the grant commands needed for all the procs in a database</p>
<br/><a href="http://www.socialmarker.com/?link=http://www.flexicoder.com/blog/index.php/2010/04/sql-grant-execute-for-stored-procs/&title=SQL+Grant+Execute+for+Stored+Procs&text=Found+this+great+article+that+has+a+really+simple+script+to+create+the+grant+commands+needed+for+all+the+procs+in+a+database...&tags=" target="_blank"><img src= "http://www.socialmarker.com/bookmark.gif" border="0" /></a><noscript><a href="http://www.socialmarker.com" >Social Bookmarking</a></noscript>]]></content:encoded>
			<wfw:commentRss>http://www.flexicoder.com/blog/index.php/2010/04/sql-grant-execute-for-stored-procs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Passing xml to use as search criteria in a query (optional parameters)</title>
		<link>http://www.flexicoder.com/blog/index.php/2009/06/passing-xml-to-use-as-search-criteria-in-a-query-optional-parameters/</link>
		<comments>http://www.flexicoder.com/blog/index.php/2009/06/passing-xml-to-use-as-search-criteria-in-a-query-optional-parameters/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 08:21:00 +0000</pubDate>
		<dc:creator>flexicoder</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[query syntax]]></category>

		<guid isPermaLink="false">http://www.flexicoder.com/blog/?p=46</guid>
		<description><![CDATA[We&#8217;ve had to generate a search facility for books on a site. The user types in any number of values and the results are ranked based on how many of the terms are actually found.
The example below has a hard coded XML data, but obviously this would be passed in as a parameter, and as [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve had to generate a search facility for books on a site. The user types in any number of values and the results are ranked based on how many of the terms are actually found.</p>
<p>The example below has a hard coded XML data, but obviously this would be passed in as a parameter, and as you build this externally you can include as many terms as you need.</p>
<p><code></p>
<pre class="brush: sql">
DECLARE @xml XML
SET @xml = '&lt;search&gt;
              &lt;term text="and" /&gt;
              &lt;term text="the" /&gt;
              &lt;term text="princess" /&gt;
              &lt;term text="9780719554285" /&gt;
            &lt;/search&gt;';

/* Use a CTE to load the terms into a table for later joining */
With MatchingTerms  (Term)
AS ( Select node.value('./@text', 'varchar(2000)') AS Term
        FROM @xml.nodes(N'//term') T(node))

SELECT  b.id,
            b.coverTitle,
            b.ISBN13,
            shortName as [binding],
            'B' as [type],
            count(id) as score
FROM    Book b,
           MatchingTerms x
WHERE
     b.coverTitle like '%' + x.Term + '%'
OR
     b.ISBN13 = x.Term
GROUP BY
     b.id,  b.coverTitle,  b.ISBN13, shortName</pre>
<p></code></p>
<br/><a href="http://www.socialmarker.com/?link=http://www.flexicoder.com/blog/index.php/2009/06/passing-xml-to-use-as-search-criteria-in-a-query-optional-parameters/&title=Passing+xml+to+use+as+search+criteria+in+a+query+%28optional+parameters%29&text=We%26%238217%3Bve+had+to+generate+a+search+facility+for+books+on+a+site.+The+user+types+in+any+number+of+values+and+the+results+are+ranked+based+on+how+many+of+the+terms+are+actually+found.&tags=" target="_blank"><img src= "http://www.socialmarker.com/bookmark.gif" border="0" /></a><noscript><a href="http://www.socialmarker.com" >Social Bookmarking</a></noscript>]]></content:encoded>
			<wfw:commentRss>http://www.flexicoder.com/blog/index.php/2009/06/passing-xml-to-use-as-search-criteria-in-a-query-optional-parameters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Differences between SCOPE_IDENTITY and @@IDENTITY</title>
		<link>http://www.flexicoder.com/blog/index.php/2009/04/scope_identity-identity/</link>
		<comments>http://www.flexicoder.com/blog/index.php/2009/04/scope_identity-identity/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 08:45:00 +0000</pubDate>
		<dc:creator>flexicoder</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[query syntax]]></category>

		<guid isPermaLink="false">http://www.flexicoder.com/blog/?p=39</guid>
		<description><![CDATA[@@IDENTITY will return the last id that was created using your connection, therefore if your insert kicks off a trigger you could get the wrong id.
But SCOPE_INDENTITY() will return the last identity created
Social Bookmarking]]></description>
			<content:encoded><![CDATA[<p>@@IDENTITY will return the last id that was created using your connection, therefore if your insert kicks off a trigger you could get the wrong id.</p>
<p>But SCOPE_INDENTITY() will return the last identity created</p>
<br/><a href="http://www.socialmarker.com/?link=http://www.flexicoder.com/blog/index.php/2009/04/scope_identity-identity/&title=Differences+between+SCOPE_IDENTITY+and+%40%40IDENTITY&text=%40%40IDENTITY+will+return+the+last+id+that+was+created+using+your+connection%2C+therefore+if+your+insert+kicks+off+a+trigger+you+could+get+the+wrong+id.&tags=" target="_blank"><img src= "http://www.socialmarker.com/bookmark.gif" border="0" /></a><noscript><a href="http://www.socialmarker.com" >Social Bookmarking</a></noscript>]]></content:encoded>
			<wfw:commentRss>http://www.flexicoder.com/blog/index.php/2009/04/scope_identity-identity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Delete with Inner join</title>
		<link>http://www.flexicoder.com/blog/index.php/2009/03/delete-with-inner-join/</link>
		<comments>http://www.flexicoder.com/blog/index.php/2009/03/delete-with-inner-join/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 11:22:00 +0000</pubDate>
		<dc:creator>flexicoder</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[query syntax]]></category>

		<guid isPermaLink="false">http://www.flexicoder.com/blog/?p=37</guid>
		<description><![CDATA[The following example shows how to perform a delete using an inner join


DELETE
    a
FROM
    StatementlineassociatedPayment AS a
INNER JOIN
    rebatePatientStatementLine AS b
ON
    a.StatementlineId = b.Id
INNER JOIN
    rebatePatientSummary AS c
ON
    b.summaryId = c.Id
WHERE
    c.IssueStatus &#60;&#62; 2

Social [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how to perform a delete using an inner join</p>
<p><code>
<pre class="brush: sql">
DELETE
    a
FROM
    StatementlineassociatedPayment AS a
INNER JOIN
    rebatePatientStatementLine AS b
ON
    a.StatementlineId = b.Id
INNER JOIN
    rebatePatientSummary AS c
ON
    b.summaryId = c.Id
WHERE
    c.IssueStatus &lt;&gt; 2</pre>
<p></code></p>
<br/><a href="http://www.socialmarker.com/?link=http://www.flexicoder.com/blog/index.php/2009/03/delete-with-inner-join/&title=Delete+with+Inner+join&text=The+following+example+shows+how+to+perform+a+delete+using+an+inner+join+++DELETE+++++a+FROM+++++StatementlineassociatedPayment+AS+a+INNER+JOIN+++++rebatePatientStatementLine+AS+b+ON++++...&tags=inner+join" target="_blank"><img src= "http://www.socialmarker.com/bookmark.gif" border="0" /></a><noscript><a href="http://www.socialmarker.com" >Social Bookmarking</a></noscript>]]></content:encoded>
			<wfw:commentRss>http://www.flexicoder.com/blog/index.php/2009/03/delete-with-inner-join/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CTE &#8211; Common Table Expression</title>
		<link>http://www.flexicoder.com/blog/index.php/2009/02/cte-common-table-expression/</link>
		<comments>http://www.flexicoder.com/blog/index.php/2009/02/cte-common-table-expression/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 19:48:00 +0000</pubDate>
		<dc:creator>flexicoder</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[query syntax]]></category>

		<guid isPermaLink="false">http://www.flexicoder.com/blog/?p=31</guid>
		<description><![CDATA[The following is an example of a CTE we have used


WITH ProcessedTasks (PatientID, LowestTaskId)
AS
(
SELECT DISTINCT
    RebatePatientSummary.PatientId,
    MIN(RebatePayment.TaskEventId) AS Expr1
FROM
    StatementLineAssociatedPayment
INNER JOIN
    RebatePayment
    ON StatementLineAssociatedPayment.RebatePaymentId = RebatePayment.Id
INNER JOIN
    RebatePatientStatementLine
    ON StatementLineAssociatedPayment.StatementLineId = RebatePatientStatementLine.Id
INNER JOIN
  [...]]]></description>
			<content:encoded><![CDATA[<p>The following is an example of a CTE we have used<br />
<code>
<pre class="brush:sql">
WITH ProcessedTasks (PatientID, LowestTaskId)
AS
(
SELECT DISTINCT
    RebatePatientSummary.PatientId,
    MIN(RebatePayment.TaskEventId) AS Expr1
FROM
    StatementLineAssociatedPayment
INNER JOIN
    RebatePayment
    ON StatementLineAssociatedPayment.RebatePaymentId = RebatePayment.Id
INNER JOIN
    RebatePatientStatementLine
    ON StatementLineAssociatedPayment.StatementLineId = RebatePatientStatementLine.Id
INNER JOIN
    RebatePatientSummary
    ON RebatePatientStatementLine.SummaryId = RebatePatientSummary.Id
INNER JOIN
    TaskEvent
    ON RebatePayment.TaskEventId = TaskEvent.Id
WHERE
    (RebatePatientSummary.IssueStatus = 2)
AND
    (RebatePayment.TaskEventId <> 0)
AND
    (TaskEvent.EventStatus = 5)
AND
    taskevent.rebateprocessed = 0
GROUP BY
    RebatePatientSummary.PatientId
)

SELECT
    t.Id,
    t.PatientId,
    t.RebateProcessed,
    p.lowestTaskId,
    t.SystemTaskId
FROM
    TaskEvent as t
INNER JOIN
    ProcessedTasks AS p
    ON t.PatientId = p.PatientId
AND
    t.Id <= p.LowestTaskId
WHERE
    EventStatus = 5
AND
    rebateprocessed = 0</pre>
<p></code></p>
<br/><a href="http://www.socialmarker.com/?link=http://www.flexicoder.com/blog/index.php/2009/02/cte-common-table-expression/&title=CTE+%26%238211%3B+Common+Table+Expression&text=The+following+is+an+example+of+a+CTE+we+have+used+++WITH+ProcessedTasks+%28PatientID%2C+LowestTaskId%29+AS+%28+SELECT+DISTINCT+++++RebatePatientSummary.PatientId%2C+++++MIN%28RebatePayment.TaskEventId%29+AS+Expr1...&tags=inner+join%2C+patientid%2C+taskevent%2C+inner%2C+rebatepayment%2C+rebatepatientsummary" target="_blank"><img src= "http://www.socialmarker.com/bookmark.gif" border="0" /></a><noscript><a href="http://www.socialmarker.com" >Social Bookmarking</a></noscript>]]></content:encoded>
			<wfw:commentRss>http://www.flexicoder.com/blog/index.php/2009/02/cte-common-table-expression/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TRUNCATE TABLE &#8211; execute permissions</title>
		<link>http://www.flexicoder.com/blog/index.php/2009/01/truncate-table-execute-permissions/</link>
		<comments>http://www.flexicoder.com/blog/index.php/2009/01/truncate-table-execute-permissions/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 15:01:00 +0000</pubDate>
		<dc:creator>flexicoder</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[query syntax]]></category>

		<guid isPermaLink="false">http://www.flexicoder.com/blog/?p=21</guid>
		<description><![CDATA[In SQL 2005 you can now use WITH EXECUTE AS to allow a normal user to truncate tables. It basically means they run the specificed procedure with higher rights than they have.


CREATE PROCEDURE TruncateMyTable
WITH EXECUTE AS OWNER
AS TRUNCATE TABLE MyDB..MyTable;


See MSDN for more details.
Social Bookmarking]]></description>
			<content:encoded><![CDATA[<p>In SQL 2005 you can now use <em>WITH EXECUTE AS </em>to allow a normal user to truncate tables. It basically means they run the specificed procedure with higher rights than they have.</p>
<p><code>
<pre class="brush: sql">
CREATE PROCEDURE TruncateMyTable
WITH EXECUTE AS OWNER
AS TRUNCATE TABLE MyDB..MyTable;
</pre>
<p></code></p>
<p>See <a href="http://msdn.microsoft.com/en-us/library/ms190384(SQL.90).aspx">MSDN</a> for more details.</p>
<br/><a href="http://www.socialmarker.com/?link=http://www.flexicoder.com/blog/index.php/2009/01/truncate-table-execute-permissions/&title=TRUNCATE+TABLE+%26%238211%3B+execute+permissions&text=In+SQL+2005+you+can+now+use+WITH+EXECUTE+AS+to+allow+a+normal+user+to+truncate+tables.+It+basically+means+they+run+the+specificed+procedure+with+higher+rights+than+they+have.&tags=" target="_blank"><img src= "http://www.socialmarker.com/bookmark.gif" border="0" /></a><noscript><a href="http://www.socialmarker.com" >Social Bookmarking</a></noscript>]]></content:encoded>
			<wfw:commentRss>http://www.flexicoder.com/blog/index.php/2009/01/truncate-table-execute-permissions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>T-SQL Update with Inner Join</title>
		<link>http://www.flexicoder.com/blog/index.php/2008/12/t-sql-update-with-inner-join/</link>
		<comments>http://www.flexicoder.com/blog/index.php/2008/12/t-sql-update-with-inner-join/#comments</comments>
		<pubDate>Fri, 19 Dec 2008 14:18:00 +0000</pubDate>
		<dc:creator>flexicoder</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[query syntax]]></category>

		<guid isPermaLink="false">http://www.flexicoder.com/blog/?p=16</guid>
		<description><![CDATA[Below is an example of an Update that has an Inner Join


UPDATE
    Taskevent
SET
    RebateProcessed = 1
FROM
    TaskEvent
INNER JOIN
    TaskEventAsset
    ON TaskEvent.Id = TaskEventAsset.Id
WHERE
    PatientId = @PatientID
AND
    JobDate < @PriorTo
AND
     ConcentratorId [...]]]></description>
			<content:encoded><![CDATA[<p>Below is an example of an Update that has an Inner Join</p>
<p><code>
<pre class="brush:sql">
UPDATE
    Taskevent
SET
    RebateProcessed = 1
FROM
    TaskEvent
INNER JOIN
    TaskEventAsset
    ON TaskEvent.Id = TaskEventAsset.Id
WHERE
    PatientId = @PatientID
AND
    JobDate < @PriorTo
AND
     ConcentratorId = @ConcentratorId</pre>
<p></code></p>
<br/><a href="http://www.socialmarker.com/?link=http://www.flexicoder.com/blog/index.php/2008/12/t-sql-update-with-inner-join/&title=T-SQL+Update+with+Inner+Join&text=Below+is+an+example+of+an+Update+that+has+an+Inner+Join+++UPDATE+++++Taskevent+SET+++++RebateProcessed+%3D+1+FROM+++++TaskEvent+INNER+JOIN+++++TaskEventAsset+++++ON+TaskEvent.Id+%3D+TaskEventAsset.Id...&tags=" target="_blank"><img src= "http://www.socialmarker.com/bookmark.gif" border="0" /></a><noscript><a href="http://www.socialmarker.com" >Social Bookmarking</a></noscript>]]></content:encoded>
			<wfw:commentRss>http://www.flexicoder.com/blog/index.php/2008/12/t-sql-update-with-inner-join/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Grant Execute</title>
		<link>http://www.flexicoder.com/blog/index.php/2008/12/sql-grant-execute/</link>
		<comments>http://www.flexicoder.com/blog/index.php/2008/12/sql-grant-execute/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 15:45:00 +0000</pubDate>
		<dc:creator>flexicoder</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[useful links]]></category>
		<category><![CDATA[query syntax]]></category>

		<guid isPermaLink="false">http://www.flexicoder.com/blog/?p=15</guid>
		<description><![CDATA[Found an article that had a nice SQL script to assign execute permissions to a user in SQL2000
Here is the script 


DECLARE @sql nvarchar(4000)

DECLARE @db  sysname ;
SET @db = DB_NAME()

DECLARE @u   sysname ;
SET @u = QUOTENAME('')

SET @sql ='select ''grant exec on ''
        + QUOTENAME(ROUTINE_SCHEMA) + [...]]]></description>
			<content:encoded><![CDATA[<p>Found an <a href="http://www.sqldbatips.com/showarticle.asp?ID=8">article</a> that had a nice SQL script to assign execute permissions to a user in SQL2000</p>
<p>Here is the script </p>
<p><code>
<pre class="brush:sql">
DECLARE @sql nvarchar(4000)

DECLARE @db  sysname ;
SET @db = DB_NAME()

DECLARE @u   sysname ;
SET @u = QUOTENAME('<insert_username>')

SET @sql ='select ''grant exec on ''
        + QUOTENAME(ROUTINE_SCHEMA) + ''.''
        + QUOTENAME(ROUTINE_NAME) + '' TO ' + @u
        + ''' FROM INFORMATION_SCHEMA.ROUTINES ' +
        'WHERE OBJECTPROPERTY(OBJECT_ID(ROUTINE_NAME),''IsMSShipped'') = 0'

EXEC master.dbo.xp_execresultset @sql,@db</pre>
<p></code></p>
<br/><a href="http://www.socialmarker.com/?link=http://www.flexicoder.com/blog/index.php/2008/12/sql-grant-execute/&title=SQL+Grant+Execute&text=Found+an+article+that+had+a+nice+SQL+script+to+assign+execute+permissions+to+a+user+in+SQL2000+Here+is+the+script++++DECLARE+%40sql+nvarchar%284000%29++DECLARE+%40db++sysname+%3B+SET+%40db+%3D+DB_NAME%28%29++DECLARE...&tags=" target="_blank"><img src= "http://www.socialmarker.com/bookmark.gif" border="0" /></a><noscript><a href="http://www.socialmarker.com" >Social Bookmarking</a></noscript>]]></content:encoded>
			<wfw:commentRss>http://www.flexicoder.com/blog/index.php/2008/12/sql-grant-execute/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
