SELECT T0.CardCode as CardCode,T0.CardName as CardName,(Select (Isnull(Sum(Credit),0)) from Jdt1 where ShortName = T0.CardCode - Select(isnull(Sum(T10.Credit),0) from [dbo].[JDT1] T10 inner Join Orct T11 on T10.TransId = T11.TransId and T11.Canceled = 'N' and
T10.ShortName = T0.CardCode) as Balance
FROM Ocrd T0 where T0.CardCode = 'C01'
When asking SQL questions always share the table schema, data, and complete query. Explain or share the expected results. Lastly format your code before posting.
More likely a non balanced closing ). Count them or edit your statement on multiple lines to better see the structure and find the culprit.
Make it work first but it seems it could be rewritten with joins and groups. I tend to avoid subqueries in the SELECT clause when possible as it is IMO often less clear.
I didn't understand your query, I don't know if you will get the expected result, but try this:
SELECT
T0.CardCode as CardCode,
T0.CardName as CardName,
(Select Isnull(Sum(Credit), 0)
from Jdt1
where ShortName = T0.CardCode) -
(Select isnull(Sum(T10.Credit), 0)
from [dbo].[JDT1] T10
inner Join Orct T11 on T10.TransId = T11.TransId where T11.Canceled = 'N' and T10.ShortName = T0.CardCode) as Balance
FROM Ocrd T0
where T0.CardCode = 'C01'
SELECT T0.CardCode as CardCode,T0.CardName as CardName,(Select (Isnull(Sum(Credit),0)) from Jdt1 where ShortName = T0.CardCode - Select(isnull(Sum(T10.Credit),0) from [dbo].[JDT1] T10 inner Join Orct T11 on T10.TransId = T11.TransId and T11.Canceled = 'N' and
T10.ShortName = T0.CardCode) as Balance
FROM Ocrd T0 where T0.CardCode = 'C01'
If you try the imapsp's code, then there is no Incorrect Syntax in compilation.
But If you still have questions, please post more information about your requirement.
Best regards,
Sam
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
140 Points
518 Posts
Incorrect Syntax near the keyword select , Incorrect Syntax near the keyword from,
Dec 19, 2019 08:26 AM|jsshivalik|LINK
Hi
Below is the query
SELECT T0.CardCode as CardCode,T0.CardName as CardName,(Select (Isnull(Sum(Credit),0)) from Jdt1 where ShortName = T0.CardCode - Select(isnull(Sum(T10.Credit),0) from [dbo].[JDT1] T10 inner Join Orct T11 on T10.TransId = T11.TransId and T11.Canceled = 'N' and T10.ShortName = T0.CardCode) as Balance
FROM Ocrd T0 where T0.CardCode = 'C01'
Thanks
All-Star
53021 Points
23607 Posts
Re: Incorrect Syntax near the keyword select , Incorrect Syntax near the keyword from,
Dec 19, 2019 11:26 AM|mgebhard|LINK
The code is incomplete.
When asking SQL questions always share the table schema, data, and complete query. Explain or share the expected results. Lastly format your code before posting.
All-Star
48510 Points
18071 Posts
Re: Incorrect Syntax near the keyword select , Incorrect Syntax near the keyword from,
Dec 19, 2019 11:53 AM|PatriceSc|LINK
Hi,
More likely a non balanced closing ). Count them or edit your statement on multiple lines to better see the structure and find the culprit.
Make it work first but it seems it could be rewritten with joins and groups. I tend to avoid subqueries in the SELECT clause when possible as it is IMO often less clear.
Participant
1120 Points
296 Posts
Re: Incorrect Syntax near the keyword select , Incorrect Syntax near the keyword from,
Dec 19, 2019 01:04 PM|imapsp|LINK
Hi,
I didn't understand your query, I don't know if you will get the expected result, but try this:
Hope this help
Contributor
3370 Points
1409 Posts
Re: Incorrect Syntax near the keyword select , Incorrect Syntax near the keyword from,
Dec 26, 2019 03:30 AM|samwu|LINK
Hi jsshivalik,
If you try the imapsp's code, then there is no Incorrect Syntax in compilation.
But If you still have questions, please post more information about your requirement.
Best regards,
Sam