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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count syntax error

Status
Not open for further replies.

mossbs

Programmer
Joined
Aug 19, 2008
Messages
102
Location
GB
Hi guys,

Got the following bit of code throwing a syntax error but no idea why....


Code:
declare @total int

set  @total =  select count(distinct member_ref)
				from membership_history
				where member_ref in (select member_ref from member where member_status = 33)
				and datename(m,valid_from) = datename(m,dateadd(m,-1,getdate()))



error is

''Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'select'.''


any ideas whats up with it? the count 'statement' runs fine on its own - just wont let me set the variable to be taht.

Having same problems when trying to update a table row to be the same.

Cheers,

Dan.

 
Missing parenthesis:

Code:
declare @total int

set  @total =  [!]([/!]select count(distinct member_ref)
                from membership_history
                where member_ref in (select member_ref from member where member_status = 33)
                and datename(m,valid_from) = datename(m,dateadd(m,-1,getdate()))[!])[/!]

Coded this way... you better make sure that there will only EVER be one row returned from the query or you will get another (different) error.


-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
select @total = count(distinct member_ref)
from ......
 
cant beleive it was only () to sort it out!! D'OH!!!

cheers buddy.

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top