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 |
|
boggyboy
Yak Posting Veteran
57 Posts |
Posted - 2012-11-01 : 12:21:19
|
| Getting a syntax error for the following in SQL 2008. Suggestions?Declare @Count intset @Count = (select count(*) from (select distinct [item] from data where [item] is not null))Nick W Saban |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2012-11-01 : 12:23:25
|
What is the error? My guess is that you need to explicitly name/alias your derived table. Something like: Declare @Count intset @Count = (select count(*) from (select distinct [item] from data where [item] is not null) AS t) |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2012-11-01 : 12:27:54
|
Just out of curiosity, what's wrong with:DECLARE @Count INTSELECT @Count = COUNT(DISTINCT item) FROM DATA WHERE [item] IS NOT NULL |
 |
|
|
boggyboy
Yak Posting Veteran
57 Posts |
Posted - 2012-11-01 : 13:17:47
|
| Thanks to both of you!Nick W Saban |
 |
|
|
|
|
|