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 2005 Forums
 Transact-SQL (2005)
 Why isn't this Table Variable Working

Author  Topic 

Dallr
Yak Posting Veteran

87 Posts

Posted - 2008-05-01 : 14:58:15
I am getting a failed error message with this code and i don't understand why.


DECLARE @YourTAble Table (AccountID INT)


Insert INTO @YourTable
SELECT 8003 UNION ALL
SELECT 8015 UNION ALL
SELECT 5033 UNION ALL
SELECT 5033 UNION ALL
SELECT 2115 UNION ALL
SELECT 2678


SELECT AccountID, Ranking =(SELECT COUNT(*) FROM @yourtable as YT WHERE YT.AccountID > @yourtable.AccountID)+ 1
FROM @YourTable
ORDER BY (SELECT COUNT(*) FROM @YourTable YT WHERE YT.AccountID > @YourTable.AccountID) + 1


Dallr

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-05-01 : 15:02:03
You can't use @yourtable.AccountID. You must use an alias instead.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page

Dallr
Yak Posting Veteran

87 Posts

Posted - 2008-05-01 : 15:08:33
Thanks Tara!!

dallr
Go to Top of Page
   

- Advertisement -