Tallan's Technology Blog

Tallan's Top Technologists Share Their Thoughts on Today's Technology Challenges

Posts Tagged "table variables"

Using Table Valued Variables instead of Dynamic SQL

I had a situation today where I have a stored procedure that is structured as follows:

1 CREATE PROCEDURE _Entity_GetByKeywordTypeDateRange( 2 @keyword varchar(255) = null, 3 @typeA bit = 0, 4 @typeB bit = 0, 5 @typeC bit = 0, 6 @startDate datetime, 7 @endDate datetime) AS 8 BEGIN 9 10 SELECT 11 EntityId, 12 TypeId, 13 — Field List 14 FROM 15 EntityTable 16 WHERE 17 — Where Clause 18 END

Due to the framework we’re using, I don’t have a lot of control over the argument list here, unfortunately.  I was trying to find out the best way to handle the bit flags.  Types A, B, and C correspond to TypeId’s 1,2, and 3 respectively.
I had toyed with using some kind of progression of OR statements…

\\\