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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 A simple variable assignment problem

Author  Topic 

james_yoder@hotmail.com
Starting Member

9 Posts

Posted - 2003-10-01 : 07:34:20
Here is a simple problem : I want to assign a variable the number of rows that meet a given view condition. Problem is when I try this I get an error.

Here is the SQL statment :

DECLARE
@MyRowCount AS Int
SET @MyRowCount = (SELECT COUNT(*) FROM v_Gallery)


Where v_Gallery is a view.

I get the following Error :
Server: Msg 8624, Level 16, State 16, Line 3
Internal SQL Server error.


I know this must have something to do with the view, but when I excute the simple command SELECT COUNT(*) FROM v_Gallery I don't get any error, and the correct number is returned.

Anyone out there have any idea why this happens?

Thanks for your help.
James

samsekar
Constraint Violating Yak Guru

437 Posts

Posted - 2003-10-01 : 07:46:44
Try this,

DECLARE
@MyRowCount AS Int
SELECT @MyRowCount =COUNT(*) FROM v_Gallery
SELECT @MyRowCount 'My Row Count'

- Sekar
Go to Top of Page

james_yoder@hotmail.com
Starting Member

9 Posts

Posted - 2003-10-01 : 08:57:50
That did it Thanks!
Go to Top of Page
   

- Advertisement -