Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Evaluating Boolean expressions using T-SQL Expand / Collapse
Author
Message
Posted Monday, November 29, 2004 1:06 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: 2 days ago @ 12:43 PM
Points: 138, Visits: 269
Comments posted to this topic are about the content posted at http://www.sqlservercentral.com


Post #148433
Posted Wednesday, December 22, 2004 3:24 AM
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Friday, September 6, 2013 2:16 AM
Points: 693, Visits: 124

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:

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

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).

Razvan

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.




Post #152125
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse