Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
skataben
Starting Member
4 Posts |
Posted - 2011-05-19 : 11:55:45
|
| My T-SQL database has a status column. I need to count the number of each status. Here are the possible values:Passed *some code*Failed *some code*No RunNARetestSkippedMy query works but is very slow (18 seconds every time):SELECT DISTINCT LEFT(statusColumn, 7) AS Status, (SELECT COUNT(statusColumn) FROM req_info WHERE LEFT(statusColumn, 7) = LEFT(outerTable.statusColumn, 7) ) AS CountFROM req_info AS outerTableGROUP BY statusColumnThe results look similar to this:Status CountFailed 4964No Run 383367Passed 18074The query is slowed down by the fact that the values 'Passed' and 'Failed' may have strings after them requiring me to do a LEFT string compare. I'm hoping some of the gurus here can help make this relatively simple query faster. |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-05-19 : 11:59:29
|
| isn't it justselect LEFT(statusColumn, 7) AS Status, count(*)FROM req_infogroup by LEFT(statusColumn, 7)==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
skataben
Starting Member
4 Posts |
Posted - 2011-05-19 : 12:10:56
|
| Ok now I'm mad haha.Seriously though, your query looks exactly like the query I came up with yesterday, but I was getting an error like 'not in aggregate function' or something (I don't remember exactly).Who cares, it works now! Thanks! |
 |
|
|
|
|
|