Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
SQL
ce
clients
clustering
connect
datamining
datawarehouse
dts
fulltext
jdbcdriver
msde
mseq
newusers
notificationsvcs
odbc
olap
programming
replication
reportingsvcs
security
securitytools
server
setup
sqlxml.viewmapper
tools
xml
  
 
date: Tue, 1 Jul 2008 14:42:03 -0500,    group: microsoft.public.sqlserver.newusers        back       


MSg 156, Level 15, State 1 error   
I am trying to execute the following query using MS SQL Server Management 
Studio (version 9.00.2047.00) on a Windows Server 2003 R2 SP2 Enterprise 
operating system:

select u.QuotaID, ab.purse,
   coalesce(ab.Balance,0) + coalesce(ab.PurgedBalance,0) +
   coalesce((select sum(Debit-Credit),0) from TranLedger tl where
 tl.acctno = a.acctno and tl.purse = ab.purse),0) as currentbalance
 from QuotaUser u
  inner join Account a on u.quotaacctno = a.acctno
  left join AccountBalance ab on a.acctno = ab.acctno

The error I get is:
Msg 156, Level 15, Line 3
Incorrect syntax near the keyword 'from'

Can anyone help me get past this?   I am new to SQL and need help with the 
syntax.  Thanks for your time!
date: Tue, 1 Jul 2008 14:42:03 -0500   author:   pucsatch alias

Re: MSg 156, Level 15, State 1 error   
Your brackets are mismatched.

-- 
Andrew J. Kelly    SQL MVP
Solid Quality Mentors


"pucsatch" <pucsatch@news.postalias> wrote in message 
news:uZNaKK72IHA.4272@TK2MSFTNGP03.phx.gbl...
>I am trying to execute the following query using MS SQL Server Management 
>Studio (version 9.00.2047.00) on a Windows Server 2003 R2 SP2 Enterprise 
>operating system:
>
> select u.QuotaID, ab.purse,
>   coalesce(ab.Balance,0) + coalesce(ab.PurgedBalance,0) +
>   coalesce((select sum(Debit-Credit),0) from TranLedger tl where
> tl.acctno = a.acctno and tl.purse = ab.purse),0) as currentbalance
> from QuotaUser u
>  inner join Account a on u.quotaacctno = a.acctno
>  left join AccountBalance ab on a.acctno = ab.acctno
>
> The error I get is:
> Msg 156, Level 15, Line 3
> Incorrect syntax near the keyword 'from'
>
> Can anyone help me get past this?   I am new to SQL and need help with the 
> syntax.  Thanks for your time!
>
date: Tue, 1 Jul 2008 16:02:35 -0400   author:   Andrew J. Kelly

Re: MSg 156, Level 15, State 1 error   
I tried this:

coalesce((select sum(Debit-Credit),0)) from TranLedger tl where

and got MSg 102, Level 15, State 1
Incorrect syntax near ')'

I thought that was what you meant by the mismatched brackets, but I'm 
obviously missing what you tried to tell me.  Anyway you can be more 
specific?  I hate to be so obtuse, but I really do not know much about 
queries.

"Andrew J. Kelly"  wrote in message 
news:O$I4pV72IHA.5024@TK2MSFTNGP03.phx.gbl...
> Your brackets are mismatched.
>
> -- 
> Andrew J. Kelly    SQL MVP
> Solid Quality Mentors
>
>
> "pucsatch" <pucsatch@news.postalias> wrote in message 
> news:uZNaKK72IHA.4272@TK2MSFTNGP03.phx.gbl...
>>I am trying to execute the following query using MS SQL Server Management 
>>Studio (version 9.00.2047.00) on a Windows Server 2003 R2 SP2 Enterprise 
>>operating system:
>>
>> select u.QuotaID, ab.purse,
>>   coalesce(ab.Balance,0) + coalesce(ab.PurgedBalance,0) +
>>   coalesce((select sum(Debit-Credit),0) from TranLedger tl where
>> tl.acctno = a.acctno and tl.purse = ab.purse),0) as currentbalance
>> from QuotaUser u
>>  inner join Account a on u.quotaacctno = a.acctno
>>  left join AccountBalance ab on a.acctno = ab.acctno
>>
>> The error I get is:
>> Msg 156, Level 15, Line 3
>> Incorrect syntax near the keyword 'from'
>>
>> Can anyone help me get past this?   I am new to SQL and need help with 
>> the syntax.  Thanks for your time!
>>
>
date: Tue, 1 Jul 2008 15:52:45 -0500   author:   pucsatch alias

Re: MSg 156, Level 15, State 1 error   
I believe you need (untested)

   coalesce(ab.Balance,0) + coalesce(ab.PurgedBalance,0) +
   coalesce((select sum(Debit-Credit) from TranLedger tl where
 tl.acctno = a.acctno and tl.purse = ab.purse),0) as currentbalance

"pucsatch" <pucsatch@news.postalias> wrote in message 
news:uJPXrx72IHA.2332@TK2MSFTNGP03.phx.gbl...
>I tried this:
>
> coalesce((select sum(Debit-Credit),0)) from TranLedger tl where
>
> and got MSg 102, Level 15, State 1
> Incorrect syntax near ')'
>
> I thought that was what you meant by the mismatched brackets, but I'm 
> obviously missing what you tried to tell me.  Anyway you can be more 
> specific?  I hate to be so obtuse, but I really do not know much about 
> queries.
>
> "Andrew J. Kelly"  wrote in message 
> news:O$I4pV72IHA.5024@TK2MSFTNGP03.phx.gbl...
>> Your brackets are mismatched.
>>
>> -- 
>> Andrew J. Kelly    SQL MVP
>> Solid Quality Mentors
>>
>>
>> "pucsatch" <pucsatch@news.postalias> wrote in message 
>> news:uZNaKK72IHA.4272@TK2MSFTNGP03.phx.gbl...
>>>I am trying to execute the following query using MS SQL Server Management 
>>>Studio (version 9.00.2047.00) on a Windows Server 2003 R2 SP2 Enterprise 
>>>operating system:
>>>
>>> select u.QuotaID, ab.purse,
>>>   coalesce(ab.Balance,0) + coalesce(ab.PurgedBalance,0) +
>>>   coalesce((select sum(Debit-Credit),0) from TranLedger tl where
>>> tl.acctno = a.acctno and tl.purse = ab.purse),0) as currentbalance
>>> from QuotaUser u
>>>  inner join Account a on u.quotaacctno = a.acctno
>>>  left join AccountBalance ab on a.acctno = ab.acctno
>>>
>>> The error I get is:
>>> Msg 156, Level 15, Line 3
>>> Incorrect syntax near the keyword 'from'
>>>
>>> Can anyone help me get past this?   I am new to SQL and need help with 
>>> the syntax.  Thanks for your time!
>>>
>>
>
>
date: Tue, 1 Jul 2008 17:00:20 -0400   author:   Tom Cooper

Re: MSg 156, Level 15, State 1 error   
In management studio, if you delete a bracket from the right end you can see 
the highlighted bracket it goes with left of it somewhere.  that is the 
simple way to match up your brackets.

-- 
Kevin G. Boles
Indicium Resources, Inc.
SQL Server MVP
kgboles a earthlink dt net


"pucsatch" <pucsatch@news.postalias> wrote in message 
news:uZNaKK72IHA.4272@TK2MSFTNGP03.phx.gbl...
>I am trying to execute the following query using MS SQL Server Management 
>Studio (version 9.00.2047.00) on a Windows Server 2003 R2 SP2 Enterprise 
>operating system:
>
> select u.QuotaID, ab.purse,
>   coalesce(ab.Balance,0) + coalesce(ab.PurgedBalance,0) +
>   coalesce((select sum(Debit-Credit),0) from TranLedger tl where
> tl.acctno = a.acctno and tl.purse = ab.purse),0) as currentbalance
> from QuotaUser u
>  inner join Account a on u.quotaacctno = a.acctno
>  left join AccountBalance ab on a.acctno = ab.acctno
>
> The error I get is:
> Msg 156, Level 15, Line 3
> Incorrect syntax near the keyword 'from'
>
> Can anyone help me get past this?   I am new to SQL and need help with the 
> syntax.  Thanks for your time!
>
date: Tue, 1 Jul 2008 16:05:42 -0500   author:   TheSQLGuru

Re: MSg 156, Level 15, State 1 error   
I got the brackets matched up but am running into another error:
Msg 116, Level 16, State 1, Line 1
Only one expression can be specified in the select list when the subquery is 
not introduced with EXISTS

Thanks again for all your help. This newsgroup has been great and I am 
really learing quite a bit.

"TheSQLGuru"  wrote in message 
news:xZGdnYdxX_lmBvfVnZ2dnUVZ_s7inZ2d@earthlink.com...
> In management studio, if you delete a bracket from the right end you can 
> see the highlighted bracket it goes with left of it somewhere.  that is 
> the simple way to match up your brackets.
>
> -- 
> Kevin G. Boles
> Indicium Resources, Inc.
> SQL Server MVP
> kgboles a earthlink dt net
>
>
> "pucsatch" <pucsatch@news.postalias> wrote in message 
> news:uZNaKK72IHA.4272@TK2MSFTNGP03.phx.gbl...
>>I am trying to execute the following query using MS SQL Server Management 
>>Studio (version 9.00.2047.00) on a Windows Server 2003 R2 SP2 Enterprise 
>>operating system:
>>
>> select u.QuotaID, ab.purse,
>>   coalesce(ab.Balance,0) + coalesce(ab.PurgedBalance,0) +
>>   coalesce((select sum(Debit-Credit),0) from TranLedger tl where
>> tl.acctno = a.acctno and tl.purse = ab.purse),0) as currentbalance
>> from QuotaUser u
>>  inner join Account a on u.quotaacctno = a.acctno
>>  left join AccountBalance ab on a.acctno = ab.acctno
>>
>> The error I get is:
>> Msg 156, Level 15, Line 3
>> Incorrect syntax near the keyword 'from'
>>
>> Can anyone help me get past this?   I am new to SQL and need help with 
>> the syntax.  Thanks for your time!
>>
>
>
date: Wed, 2 Jul 2008 15:56:14 -0500   author:   pucsatch alias

Re: MSg 156, Level 15, State 1 error   
Can you please post the current state of the entire query?

-- 
Kevin G. Boles
Indicium Resources, Inc.
SQL Server MVP
kgboles a earthlink dt net


"pucsatch" <pucsatch@news.postalias> wrote in message 
news:uyD0RYI3IHA.3728@TK2MSFTNGP03.phx.gbl...
>I got the brackets matched up but am running into another error:
> Msg 116, Level 16, State 1, Line 1
> Only one expression can be specified in the select list when the subquery 
> is not introduced with EXISTS
>
> Thanks again for all your help. This newsgroup has been great and I am 
> really learing quite a bit.
>
> "TheSQLGuru"  wrote in message 
> news:xZGdnYdxX_lmBvfVnZ2dnUVZ_s7inZ2d@earthlink.com...
>> In management studio, if you delete a bracket from the right end you can 
>> see the highlighted bracket it goes with left of it somewhere.  that is 
>> the simple way to match up your brackets.
>>
>> -- 
>> Kevin G. Boles
>> Indicium Resources, Inc.
>> SQL Server MVP
>> kgboles a earthlink dt net
>>
>>
>> "pucsatch" <pucsatch@news.postalias> wrote in message 
>> news:uZNaKK72IHA.4272@TK2MSFTNGP03.phx.gbl...
>>>I am trying to execute the following query using MS SQL Server Management 
>>>Studio (version 9.00.2047.00) on a Windows Server 2003 R2 SP2 Enterprise 
>>>operating system:
>>>
>>> select u.QuotaID, ab.purse,
>>>   coalesce(ab.Balance,0) + coalesce(ab.PurgedBalance,0) +
>>>   coalesce((select sum(Debit-Credit),0) from TranLedger tl where
>>> tl.acctno = a.acctno and tl.purse = ab.purse),0) as currentbalance
>>> from QuotaUser u
>>>  inner join Account a on u.quotaacctno = a.acctno
>>>  left join AccountBalance ab on a.acctno = ab.acctno
>>>
>>> The error I get is:
>>> Msg 156, Level 15, Line 3
>>> Incorrect syntax near the keyword 'from'
>>>
>>> Can anyone help me get past this?   I am new to SQL and need help with 
>>> the syntax.  Thanks for your time!
>>>
>>
>>
>
>
>
date: Wed, 2 Jul 2008 17:01:38 -0500   author:   TheSQLGuru

Re: MSg 156, Level 15, State 1 error   
Sure!  Here you go:

select u.QuotaID, ab.purse,
 coalesce(ab.Balance,0) + coalesce(ab.PurgedBalance,0) +
 coalesce((select sum(Debit-Credit),0 from TranLedger tl where
tl.acctno = a.acctno and tl.purse = ab.purse),0) as currentbalance
from QuotaUser u
 inner join Account a on u.quotaacctno = a.acctno
 left join AccountBalance ab on a.acctno = ab.acctno


Msg 116, Level 16, State 1, Line 1
Only one expression can be specified in the select list when the subquery is 
not introduced with EXISTS.
Msg 116, Level 16, State 1, Line 1
Only one expression can be specified in the select list when the subquery is 
not introduced with EXISTS.

"TheSQLGuru"  wrote in message 
news:daadnV_MJrALZ_bVnZ2dnUVZ_ovinZ2d@earthlink.com...
> Can you please post the current state of the entire query?
>
> -- 
> Kevin G. Boles
> Indicium Resources, Inc.
> SQL Server MVP
> kgboles a earthlink dt net
>
>
> "pucsatch" <pucsatch@news.postalias> wrote in message 
> news:uyD0RYI3IHA.3728@TK2MSFTNGP03.phx.gbl...
>>I got the brackets matched up but am running into another error:
>> Msg 116, Level 16, State 1, Line 1
>> Only one expression can be specified in the select list when the subquery 
>> is not introduced with EXISTS
>>
>> Thanks again for all your help. This newsgroup has been great and I am 
>> really learing quite a bit.
>>
>> "TheSQLGuru"  wrote in message 
>> news:xZGdnYdxX_lmBvfVnZ2dnUVZ_s7inZ2d@earthlink.com...
>>> In management studio, if you delete a bracket from the right end you can 
>>> see the highlighted bracket it goes with left of it somewhere.  that is 
>>> the simple way to match up your brackets.
>>>
>>> -- 
>>> Kevin G. Boles
>>> Indicium Resources, Inc.
>>> SQL Server MVP
>>> kgboles a earthlink dt net
>>>
>>>
>>> "pucsatch" <pucsatch@news.postalias> wrote in message 
>>> news:uZNaKK72IHA.4272@TK2MSFTNGP03.phx.gbl...
>>>>I am trying to execute the following query using MS SQL Server 
>>>>Management Studio (version 9.00.2047.00) on a Windows Server 2003 R2 SP2 
>>>>Enterprise operating system:
>>>>
>>>> select u.QuotaID, ab.purse,
>>>>   coalesce(ab.Balance,0) + coalesce(ab.PurgedBalance,0) +
>>>>   coalesce((select sum(Debit-Credit),0) from TranLedger tl where
>>>> tl.acctno = a.acctno and tl.purse = ab.purse),0) as currentbalance
>>>> from QuotaUser u
>>>>  inner join Account a on u.quotaacctno = a.acctno
>>>>  left join AccountBalance ab on a.acctno = ab.acctno
>>>>
>>>> The error I get is:
>>>> Msg 156, Level 15, Line 3
>>>> Incorrect syntax near the keyword 'from'
>>>>
>>>> Can anyone help me get past this?   I am new to SQL and need help with 
>>>> the syntax.  Thanks for your time!
>>>>
>>>
>>>
>>
>>
>>
>
>
date: Thu, 3 Jul 2008 08:57:36 -0500   author:   pucsatch alias

Re: MSg 156, Level 15, State 1 error   
I would say you need to move the aggregate out to it's own query in a 
derived table and join to it.  There are likely other solutions as well.

-- 
Kevin G. Boles
Indicium Resources, Inc.
SQL Server MVP
kgboles a earthlink dt net


"pucsatch" <pucsatch@news.postalias> wrote in message 
news:%23NaLBTR3IHA.5112@TK2MSFTNGP03.phx.gbl...
> Sure!  Here you go:
>
> select u.QuotaID, ab.purse,
> coalesce(ab.Balance,0) + coalesce(ab.PurgedBalance,0) +
> coalesce((select sum(Debit-Credit),0 from TranLedger tl where
> tl.acctno = a.acctno and tl.purse = ab.purse),0) as currentbalance
> from QuotaUser u
> inner join Account a on u.quotaacctno = a.acctno
> left join AccountBalance ab on a.acctno = ab.acctno
>
>
> Msg 116, Level 16, State 1, Line 1
> Only one expression can be specified in the select list when the subquery 
> is not introduced with EXISTS.
> Msg 116, Level 16, State 1, Line 1
> Only one expression can be specified in the select list when the subquery 
> is not introduced with EXISTS.
>
> "TheSQLGuru"  wrote in message 
> news:daadnV_MJrALZ_bVnZ2dnUVZ_ovinZ2d@earthlink.com...
>> Can you please post the current state of the entire query?
>>
>> -- 
>> Kevin G. Boles
>> Indicium Resources, Inc.
>> SQL Server MVP
>> kgboles a earthlink dt net
>>
>>
>> "pucsatch" <pucsatch@news.postalias> wrote in message 
>> news:uyD0RYI3IHA.3728@TK2MSFTNGP03.phx.gbl...
>>>I got the brackets matched up but am running into another error:
>>> Msg 116, Level 16, State 1, Line 1
>>> Only one expression can be specified in the select list when the 
>>> subquery is not introduced with EXISTS
>>>
>>> Thanks again for all your help. This newsgroup has been great and I am 
>>> really learing quite a bit.
>>>
>>> "TheSQLGuru"  wrote in message 
>>> news:xZGdnYdxX_lmBvfVnZ2dnUVZ_s7inZ2d@earthlink.com...
>>>> In management studio, if you delete a bracket from the right end you 
>>>> can see the highlighted bracket it goes with left of it somewhere. 
>>>> that is the simple way to match up your brackets.
>>>>
>>>> -- 
>>>> Kevin G. Boles
>>>> Indicium Resources, Inc.
>>>> SQL Server MVP
>>>> kgboles a earthlink dt net
>>>>
>>>>
>>>> "pucsatch" <pucsatch@news.postalias> wrote in message 
>>>> news:uZNaKK72IHA.4272@TK2MSFTNGP03.phx.gbl...
>>>>>I am trying to execute the following query using MS SQL Server 
>>>>>Management Studio (version 9.00.2047.00) on a Windows Server 2003 R2 
>>>>>SP2 Enterprise operating system:
>>>>>
>>>>> select u.QuotaID, ab.purse,
>>>>>   coalesce(ab.Balance,0) + coalesce(ab.PurgedBalance,0) +
>>>>>   coalesce((select sum(Debit-Credit),0) from TranLedger tl where
>>>>> tl.acctno = a.acctno and tl.purse = ab.purse),0) as currentbalance
>>>>> from QuotaUser u
>>>>>  inner join Account a on u.quotaacctno = a.acctno
>>>>>  left join AccountBalance ab on a.acctno = ab.acctno
>>>>>
>>>>> The error I get is:
>>>>> Msg 156, Level 15, Line 3
>>>>> Incorrect syntax near the keyword 'from'
>>>>>
>>>>> Can anyone help me get past this?   I am new to SQL and need help with 
>>>>> the syntax.  Thanks for your time!
>>>>>
>>>>
>>>>
>>>
>>>
>>>
>>
>>
>
>
date: Thu, 3 Jul 2008 09:05:07 -0500   author:   TheSQLGuru

Re: MSg 156, Level 15, State 1 error   
Great idea!  I will work on that today.  Thanks again for all your help. 
You've been very kind to a noobie.  :)


"TheSQLGuru"  wrote in message 
news:X4CdnavNMKbwQfHVnZ2dnUVZ_v_inZ2d@earthlink.com...
>I would say you need to move the aggregate out to it's own query in a 
>derived table and join to it.  There are likely other solutions as well.
>
> -- 
> Kevin G. Boles
> Indicium Resources, Inc.
> SQL Server MVP
> kgboles a earthlink dt net
>
>
> "pucsatch" <pucsatch@news.postalias> wrote in message 
> news:%23NaLBTR3IHA.5112@TK2MSFTNGP03.phx.gbl...
>> Sure!  Here you go:
>>
>> select u.QuotaID, ab.purse,
>> coalesce(ab.Balance,0) + coalesce(ab.PurgedBalance,0) +
>> coalesce((select sum(Debit-Credit),0 from TranLedger tl where
>> tl.acctno = a.acctno and tl.purse = ab.purse),0) as currentbalance
>> from QuotaUser u
>> inner join Account a on u.quotaacctno = a.acctno
>> left join AccountBalance ab on a.acctno = ab.acctno
>>
>>
>> Msg 116, Level 16, State 1, Line 1
>> Only one expression can be specified in the select list when the subquery 
>> is not introduced with EXISTS.
>> Msg 116, Level 16, State 1, Line 1
>> Only one expression can be specified in the select list when the subquery 
>> is not introduced with EXISTS.
>>
>> "TheSQLGuru"  wrote in message 
>> news:daadnV_MJrALZ_bVnZ2dnUVZ_ovinZ2d@earthlink.com...
>>> Can you please post the current state of the entire query?
>>>
>>> -- 
>>> Kevin G. Boles
>>> Indicium Resources, Inc.
>>> SQL Server MVP
>>> kgboles a earthlink dt net
>>>
>>>
>>> "pucsatch" <pucsatch@news.postalias> wrote in message 
>>> news:uyD0RYI3IHA.3728@TK2MSFTNGP03.phx.gbl...
>>>>I got the brackets matched up but am running into another error:
>>>> Msg 116, Level 16, State 1, Line 1
>>>> Only one expression can be specified in the select list when the 
>>>> subquery is not introduced with EXISTS
>>>>
>>>> Thanks again for all your help. This newsgroup has been great and I am 
>>>> really learing quite a bit.
>>>>
>>>> "TheSQLGuru"  wrote in message 
>>>> news:xZGdnYdxX_lmBvfVnZ2dnUVZ_s7inZ2d@earthlink.com...
>>>>> In management studio, if you delete a bracket from the right end you 
>>>>> can see the highlighted bracket it goes with left of it somewhere. 
>>>>> that is the simple way to match up your brackets.
>>>>>
>>>>> -- 
>>>>> Kevin G. Boles
>>>>> Indicium Resources, Inc.
>>>>> SQL Server MVP
>>>>> kgboles a earthlink dt net
>>>>>
>>>>>
>>>>> "pucsatch" <pucsatch@news.postalias> wrote in message 
>>>>> news:uZNaKK72IHA.4272@TK2MSFTNGP03.phx.gbl...
>>>>>>I am trying to execute the following query using MS SQL Server 
>>>>>>Management Studio (version 9.00.2047.00) on a Windows Server 2003 R2 
>>>>>>SP2 Enterprise operating system:
>>>>>>
>>>>>> select u.QuotaID, ab.purse,
>>>>>>   coalesce(ab.Balance,0) + coalesce(ab.PurgedBalance,0) +
>>>>>>   coalesce((select sum(Debit-Credit),0) from TranLedger tl where
>>>>>> tl.acctno = a.acctno and tl.purse = ab.purse),0) as currentbalance
>>>>>> from QuotaUser u
>>>>>>  inner join Account a on u.quotaacctno = a.acctno
>>>>>>  left join AccountBalance ab on a.acctno = ab.acctno
>>>>>>
>>>>>> The error I get is:
>>>>>> Msg 156, Level 15, Line 3
>>>>>> Incorrect syntax near the keyword 'from'
>>>>>>
>>>>>> Can anyone help me get past this?   I am new to SQL and need help 
>>>>>> with the syntax.  Thanks for your time!
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
date: Thu, 3 Jul 2008 09:25:11 -0500   author:   pucsatch alias

Re: MSg 156, Level 15, State 1 error   
I got it working.  In case anyone is interested, here is the query:

select u.QuotaID, ab.purse, p.pursename,
   coalesce(ab.Balance,0) + coalesce(ab.PurgedBalance,0) +
   coalesce((select sum(Debit-Credit) from TranLedger tl where tl.acctno = 
a.acctno and tl.purse = ab.purse),0) as currentbalance
from QuotaUser u
  inner join Account a on u.quotaacctno = a.acctno
  left join AccountBalance ab on a.acctno = ab.acctno
  inner join Purse p on ab.purse = p.purse

Thanks again for all your help!

"pucsatch" <pucsatch@news.postalias> wrote in message 
news:eKkNbiR3IHA.3500@TK2MSFTNGP05.phx.gbl...
> Great idea!  I will work on that today.  Thanks again for all your help. 
> You've been very kind to a noobie.  :)
>
>
> "TheSQLGuru"  wrote in message 
> news:X4CdnavNMKbwQfHVnZ2dnUVZ_v_inZ2d@earthlink.com...
>>I would say you need to move the aggregate out to it's own query in a 
>>derived table and join to it.  There are likely other solutions as well.
>>
>> -- 
>> Kevin G. Boles
>> Indicium Resources, Inc.
>> SQL Server MVP
>> kgboles a earthlink dt net
>>
>>
>> "pucsatch" <pucsatch@news.postalias> wrote in message 
>> news:%23NaLBTR3IHA.5112@TK2MSFTNGP03.phx.gbl...
>>> Sure!  Here you go:
>>>
>>> select u.QuotaID, ab.purse,
>>> coalesce(ab.Balance,0) + coalesce(ab.PurgedBalance,0) +
>>> coalesce((select sum(Debit-Credit),0 from TranLedger tl where
>>> tl.acctno = a.acctno and tl.purse = ab.purse),0) as currentbalance
>>> from QuotaUser u
>>> inner join Account a on u.quotaacctno = a.acctno
>>> left join AccountBalance ab on a.acctno = ab.acctno
>>>
>>>
>>> Msg 116, Level 16, State 1, Line 1
>>> Only one expression can be specified in the select list when the 
>>> subquery is not introduced with EXISTS.
>>> Msg 116, Level 16, State 1, Line 1
>>> Only one expression can be specified in the select list when the 
>>> subquery is not introduced with EXISTS.
>>>
>>> "TheSQLGuru"  wrote in message 
>>> news:daadnV_MJrALZ_bVnZ2dnUVZ_ovinZ2d@earthlink.com...
>>>> Can you please post the current state of the entire query?
>>>>
>>>> -- 
>>>> Kevin G. Boles
>>>> Indicium Resources, Inc.
>>>> SQL Server MVP
>>>> kgboles a earthlink dt net
>>>>
>>>>
>>>> "pucsatch" <pucsatch@news.postalias> wrote in message 
>>>> news:uyD0RYI3IHA.3728@TK2MSFTNGP03.phx.gbl...
>>>>>I got the brackets matched up but am running into another error:
>>>>> Msg 116, Level 16, State 1, Line 1
>>>>> Only one expression can be specified in the select list when the 
>>>>> subquery is not introduced with EXISTS
>>>>>
>>>>> Thanks again for all your help. This newsgroup has been great and I am 
>>>>> really learing quite a bit.
>>>>>
>>>>> "TheSQLGuru"  wrote in message 
>>>>> news:xZGdnYdxX_lmBvfVnZ2dnUVZ_s7inZ2d@earthlink.com...
>>>>>> In management studio, if you delete a bracket from the right end you 
>>>>>> can see the highlighted bracket it goes with left of it somewhere. 
>>>>>> that is the simple way to match up your brackets.
>>>>>>
>>>>>> -- 
>>>>>> Kevin G. Boles
>>>>>> Indicium Resources, Inc.
>>>>>> SQL Server MVP
>>>>>> kgboles a earthlink dt net
>>>>>>
>>>>>>
>>>>>> "pucsatch" <pucsatch@news.postalias> wrote in message 
>>>>>> news:uZNaKK72IHA.4272@TK2MSFTNGP03.phx.gbl...
>>>>>>>I am trying to execute the following query using MS SQL Server 
>>>>>>>Management Studio (version 9.00.2047.00) on a Windows Server 2003 R2 
>>>>>>>SP2 Enterprise operating system:
>>>>>>>
>>>>>>> select u.QuotaID, ab.purse,
>>>>>>>   coalesce(ab.Balance,0) + coalesce(ab.PurgedBalance,0) +
>>>>>>>   coalesce((select sum(Debit-Credit),0) from TranLedger tl where
>>>>>>> tl.acctno = a.acctno and tl.purse = ab.purse),0) as currentbalance
>>>>>>> from QuotaUser u
>>>>>>>  inner join Account a on u.quotaacctno = a.acctno
>>>>>>>  left join AccountBalance ab on a.acctno = ab.acctno
>>>>>>>
>>>>>>> The error I get is:
>>>>>>> Msg 156, Level 15, Line 3
>>>>>>> Incorrect syntax near the keyword 'from'
>>>>>>>
>>>>>>> Can anyone help me get past this?   I am new to SQL and need help 
>>>>>>> with the syntax.  Thanks for your time!
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
date: Thu, 3 Jul 2008 11:13:09 -0500   author:   pucsatch alias

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us