Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TSQL query

Status
Not open for further replies.

JimFL

Programmer
Jun 17, 2005
131
GB
Hi,

Is there a quicker way using tsql to perform this operation in a single query.

select count(tID)as f into #t from X group by tID
select count(f) from #t

Would appreciate anybodies thoughts on this.

Many thanks in advance.

 
Unless you just have to put the count into a temp table:

Code:
select count(tID)[s]as f into #t[/s] from X [s]group by tID[/s]

< M!ke >
Acupuncture Development: a jab well done.
 
Thanks for your help however my table x looks like this and your query doesnt produce my required results.


TABLE x

xID tID
1 1
2 1
3 2
4 2
5 3

So I would be looking to get back just the a count of the different values of tID - in this case 3.

Does that help my scenario?




 
Code:
select count(Distinct tID) as f from X

Code:
Select Count(f)
From   (
       select count(tID)as f 
       from   X 
       group by tID
       ) As A

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Jim - yes, that would have been helpful info.

And thanks for picking up my slack (again!), George!

< M!ke >
Acupuncture Development: a jab well done.
 
Slacker! [bigsmile]

Seriously though, if JimFL had posted some sample data, I have no doubt you would have gotten it right the first time.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Thanks, George! I just copied and pasted your comment into my resume! ;-)

< M!ke >
Acupuncture Development: a jab well done.
 
I think Jim gave plenty of information. His desired results are implicit in the transformations occurring in his sample queries.

[COLOR=#aa88aa black]Cum catapultae proscriptae erunt tum soli proscript catapultas habebunt.[/color]
 
Um, no:


Specifically:

13. If you are asking a question related to a SQL statement, please post the SQL statement and include relevant table layouts, relational information and sample data.

14. Provide sample result (or desired result) of your SQL statement.


It's a lot easier to understand the question when someone's already solved the problem.

< M!ke >
Acupuncture Development: a jab well done.
 
Many thanks for your help on this problem. The solution above from gmmastros has resolved my issue.

Apologies for the lack of information first time round, I will make sure that I am clearer in the future.

Thanks all

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top