﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Discuss Content Posted by Leo Peysakhovich / Article Discussions / Article Discussions by Author  / Evaluating Boolean expressions using T-SQL / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Thu, 20 Jun 2013 06:24:51 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Evaluating Boolean expressions using T-SQL</title><link>http://www.sqlservercentral.com/Forums/Topic148433-163-1.aspx</link><description>&lt;P&gt;The first part of the procedure is good enough, but a better solution could be done for the final evaluation. Instead of using a temporary table, we can use output parameters in the sp_executesql procedure, like this:&lt;/P&gt;&lt;PRE&gt;&lt;FONT color=#1111ff&gt;SET @boolExp='SELECT @res=CASE ABS(' + @boolExp + ') WHEN 1 THEN ''TRUE'' ELSE ''FALSE'' END'EXEC sp_executesql @boolExp, N' @res varchar(5) OUTPUT', @res OUTPUT&lt;/FONT&gt;&lt;FONT color=#1111ff&gt;&lt;/PRE&gt;&lt;/FONT&gt;&lt;P&gt;This way, we replace about 5 lines of code with only 2 and avoid the overhead of using a temporary table. To use the sp_executesql procedure we need to change the type of the @boolExp parameter to nvarchar(300) instead of varchar(300).&lt;/P&gt;&lt;P&gt;Razvan&lt;/P&gt;&lt;P&gt;PS. The SET NOCOUNT OFF and the DROP TABLE #temp at the end of the procedure are useless (because they are done anyway, automatically). Also useless is the big BEGIN/END block that contains the entire procedure.&lt;/P&gt;</description><pubDate>Wed, 22 Dec 2004 03:24:00 GMT</pubDate><dc:creator>Razvan Socol</dc:creator></item><item><title>Evaluating Boolean expressions using T-SQL</title><link>http://www.sqlservercentral.com/Forums/Topic148433-163-1.aspx</link><description>Comments posted to this topic are about the content posted at &lt;A HREF=http://www.sqlservercentral.com/columnists/lPeysakhovich/evaluatingbooleanexpressionsusingtsql.asp&gt;http://www.sqlservercentral.com</description><pubDate>Mon, 29 Nov 2004 13:06:00 GMT</pubDate><dc:creator>Leo Peysakhovich</dc:creator></item></channel></rss>