sub selecting the result set

  • Hi all!

    How Can I just select Col1 from the resultset of the  query below? I need to use that in another SP

    select top 1 count(col1), col1

    from tabl1

    where (col2 = 666)

    group by col1

    thanks

  • What can be modified?

    Can you show us how you're gonna use this?

  • The query returns i value in the col2 (the count), 1 value in the col 1. I just have to select the col1 value and use it in a SP

  • Sounds like homework to me...

    Declare @value as int

    select top 1 @value = col1

    from tabl1

    where (col2 = 666)

    group by col1

    Set @value = --do what you got to do with it.

  • Here is a silly way to do it although I am not a big fan of temp tables:

    select top 1 count(col1)as num, col1

    INTO #temp1

    from tabl1

    where (col2 = 666)

    group by col1

    SELECT col1 from #temp1

    DROP TABLE #temp1

  • I'd just copy the statement, or make it into a view and use it in both sps.... there's just no need for a temp table in this case, the statement is just too simple... and should run pretty fast too.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply