June 10, 2005 at 11:43 am
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
June 10, 2005 at 11:49 am
What can be modified?
Can you show us how you're gonna use this?
June 10, 2005 at 11:59 am
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
June 10, 2005 at 12:02 pm
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.
June 10, 2005 at 12:31 pm
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
June 10, 2005 at 12:32 pm
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