Hi, I'm just starting out with SQL. I'm wondering why this nested query
doesn't work. I'm sure it's something simple but I'm not sure what. Hope
somebody can shed some light.
Thanks in advance
Ant
SELECT myDate,
SUM(deposit)
FROM
(
SELECT CAST(DATENAME(MONTH,date)+ '' + DATENAME(YEAR,date)as datetime) as
[myDate],
deposit
FROM loan_tbl
)
GROUP BY myDateGot it, I neglected to give the nested query an alias. Woops. Thanks anyway.
"Ant" wrote:
> Hi, I'm just starting out with SQL. I'm wondering why this nested query
> doesn't work. I'm sure it's something simple but I'm not sure what. Hope
> somebody can shed some light.
> Thanks in advance
> Ant
>
> SELECT myDate,
> SUM(deposit)
> FROM
> (
> SELECT CAST(DATENAME(MONTH,date)+ '' + DATENAME(YEAR,date)as datetime) as
> [myDate],
> deposit
> FROM loan_tbl
> )
> GROUP BY myDate|||Simply give an alias to the sub query
Roji. P. Thomas
Net Asset Management
https://www.netassetmanagement.com
"Ant" <Ant@.discussions.microsoft.com> wrote in message
news:6433B30C-3144-4277-A495-C38D2F2B22F2@.microsoft.com...
> Hi, I'm just starting out with SQL. I'm wondering why this nested query
> doesn't work. I'm sure it's something simple but I'm not sure what. Hope
> somebody can shed some light.
> Thanks in advance
> Ant
>
> SELECT myDate,
> SUM(deposit)
> FROM
> (
> SELECT CAST(DATENAME(MONTH,date)+ '' + DATENAME(YEAR,date)as datetime) as
> [myDate],
> deposit
> FROM loan_tbl
> )
> GROUP BY myDate|||This should be treated as a derived table:
SELECT myDate, SUM(deposit)
FROM (
SELECT CAST(DATENAME(MONTH,date)+ '' + DATENAME(YEAR,date)as
datetime) as [myDate], deposit
FROM loan_tbl
) AS DerivedTable
GROUP BY myDate
best Regards,
Chandra
http://chanduas.blogspot.com/
http://groups.msn.com/SQLResource/
---
"Ant" wrote:
> Hi, I'm just starting out with SQL. I'm wondering why this nested query
> doesn't work. I'm sure it's something simple but I'm not sure what. Hope
> somebody can shed some light.
> Thanks in advance
> Ant
>
> SELECT myDate,
> SUM(deposit)
> FROM
> (
> SELECT CAST(DATENAME(MONTH,date)+ '' + DATENAME(YEAR,date)as datetime) as
> [myDate],
> deposit
> FROM loan_tbl
> )
> GROUP BY myDate
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment