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)
 possible to have a select in the FROM ?

Author  Topic 

fabianus76
Posting Yak Master

191 Posts

Posted - 2006-02-24 : 15:37:18
Hello guys!

In Access you may have a select in the "FROM" section, instead of a table. Is this possible in SQL-SERVER 2005?

Here is an example that gives me the error "Incorrect syntax near the keyword 'GROUP'." :

SELECT
LogCreateDate, count(LogUserName) as LoggedUsers

FROM

(SELECT distinct
dbo.EventLog.LogCreateDate,
dbo.EventLog.LogUserName
FROM
dbo.EventLog
WHERE
dbo.EventLog.LogTypeKey = 'Login_Success')

GROUP BY
LogCreateDate

Thank you very much for any help !

Regards,
Fabian

my favorit hoster is ASPnix : www.aspnix.com !

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-02-24 : 15:38:48
Yes it is possible, but you must alias the derived table.


SELECT LogCreateDate, count(LogUserName) as LoggedUsers
FROM
(
SELECT distinct dbo.EventLog.LogCreateDate, dbo.EventLog.LogUserName
FROM dbo.EventLog
WHERE dbo.EventLog.LogTypeKey = 'Login_Success'
) t
GROUP BY LogCreateDate


t is the alias that I have used.

Tara Kizer
aka tduggan
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-02-24 : 15:38:52
I think u have to have alias

Select ... from (select ... from ...) as Q1
Go to Top of Page

fabianus76
Posting Yak Master

191 Posts

Posted - 2006-02-24 : 15:53:51
Hi Tara, Hi Srinika,

thank you for your prompt responses !

It is really inscribable how fast the responses come in this forum – thank you for this great job!

Regards,
Fabian

my favorit hoster is ASPnix : www.aspnix.com !
Go to Top of Page
   

- Advertisement -