How do I Query the Result Set of a Query in MS SQL 2000
Posted on 2007-11-22
I'd like some advice on how to create a query.
In my stored procedure, I've got several variables which are used to form a query. The query is created as a string and then executed:
CREATE PROCEDURE [dbo].[prcGetUCC]
-- Declare input paramters
@SortExp VARCHAR(100) = NULL,
@Branch VARCHAR(20) = NULL,
@BranchJ VARCHAR(20) = NULL
IF @Branch ='All'
SET @SQLStatement='SELECT * FROM vUCC ORDER BY ' + @SortExp + ' ASC'
SET @SQLStatement='SELECT * FROM vUCC WHERE BoO = ''' + @BranchJ + ''' OR
BoO = ''' + @Branch1 + ''' OR BoO = ''' + @Branch9 + ''' ORDER BY ' + @SortExp + ' ASC'
What I want to do is then query the results of this query and further filter the data. Something like this:
SELECT * FROM (The Result Set of the Previous Query) WHERE ColumnA = ValueB
Is this at all possible?