Unix Technical Forum

Scope in derived tables

This is a discussion on Scope in derived tables within the SQL Server forums, part of the Microsoft SQL Server category; --> This is kind of what I'm trying to do in my MS SQL 2000 query. Should I be able ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-01-2008, 03:24 PM
Stephen2
 
Posts: n/a
Default Scope in derived tables

This is kind of what I'm trying to do in my MS SQL 2000 query. Should
I be able to reference s1.col1 inside the 2nd derived table?

I'm getting 'Invalid column name col1' and it's coming from the 2nd
derived table (I've commented out other refs to just it to check).

Maybe I need to use a temp table instead.


SELECT s1.col1,

(SELECT * FROM

(SELECT COUNT(zzz) AS SomeTotal
FROM tab1
WHERE s1.col1 = zzz)) AS RowCount) /* error here */

FROM
(SELECT col1 FROM table) AS s1


Thank you!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-01-2008, 03:24 PM
Erland Sommarskog
 
Posts: n/a
Default Re: Scope in derived tables

Stephen2 (Stephen@mailinator.com) writes:
> This is kind of what I'm trying to do in my MS SQL 2000 query. Should
> I be able to reference s1.col1 inside the 2nd derived table?
>
> I'm getting 'Invalid column name col1' and it's coming from the 2nd
> derived table (I've commented out other refs to just it to check).
>
> Maybe I need to use a temp table instead.
>
>
> SELECT s1.col1,
>
> (SELECT * FROM
>
> (SELECT COUNT(zzz) AS SomeTotal
> FROM tab1
> WHERE s1.col1 = zzz)) AS RowCount) /* error here */
>
> FROM
> (SELECT col1 FROM table) AS s1


Yes, you should be able to, and in SQL 2005 you are. But in SQL 2000 there
is a bug that gets in the way. It seems that you will have to resort to
a temp table.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:07 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com