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
 General SQL Server Forums
 Script Library
 Subquery as Column

Author  Topic 

Kelapa
Starting Member

8 Posts

Posted - 2013-04-12 : 03:43:23
What am I doing wrong?

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-12 : 03:48:38
I think subquery(GPAD) is returning more than one row...
Subquery must return only one value per row

NOTE:
You can't use column alias in the GROUP BY clause ( in SQL Server)
Go to Top of Page

Kelapa
Starting Member

8 Posts

Posted - 2013-04-12 : 04:11:40
quote:
Originally posted by bandi

I think subquery(GPAD) is returning more than one row...
Subquery must return only one value per row

NOTE:
You can't use column alias in the GROUP BY clause ( in SQL Server)


But I can get results separately from my two queries if I run them one by one.
Go to Top of Page

Kelapa
Starting Member

8 Posts

Posted - 2013-04-12 : 04:26:22
quote:
Originally posted by bandi

I think subquery(GPAD) is returning more than one row...
Subquery must return only one value per row


Btw, You totally right about that!
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-12 : 04:36:50
Yes you can get by separate queries....

--May be try this...
SELECT e.Gk_2, (SELECT MAX(Gecoust.ad from Gecoust where Gecoust.Evrakno = 'STKGK2') as GPAD
from stok00 e where e.kod like 'SAC SIL%'
--GROUP BY e.Gk_2

If this is not, post us the structures of those two tables and sample data as well as expected output
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-12 : 04:49:32
You can get quick response by posting respective forums...
Refere these links
http://cs.pervasive.com/forums/p/13892/47794.aspx#47794
http://cs.pervasive.com/search/SearchResults.aspx?q=Invalid+Row-count
Go to Top of Page

Kelapa
Starting Member

8 Posts

Posted - 2013-04-12 : 04:58:12
quote:
If this is not, post us the structures of those two tables and sample data as well as expected output


Thanks a lot for your effort, I handled the issue that I snuggled to handle. But I believe that I will get another issue soon while I get in some details script more.

Here is the solving
SELECT e.Gk_2, f.ad
from Stok00 e LEFT OUTER JOIN Gecoust f on e.Gk_2 = f.kod
where e.kod like 'SAC SIL%' and f.Evrakno = 'STKGK2' group by e.GK_2, f.ad
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-12 : 05:40:35
quote:
Originally posted by Kelapa

quote:
If this is not, post us the structures of those two tables and sample data as well as expected output


Thanks a lot for your effort, I handled the issue that I snuggled to handle. But I believe that I will get another issue soon while I get in some details script more.

Here is the solving
SELECT e.Gk_2, f.ad
from Stok00 e LEFT OUTER JOIN Gecoust f on e.Gk_2 = f.kod
where e.kod like 'SAC SIL%' and f.Evrakno = 'STKGK2' group by e.GK_2, f.ad



Welcome
Here you can avoid duplicates by using DISTINCT keyword rather than GROUP BY ...

SELECT DISTINCT e.Gk_2, f.ad
from Stok00 e LEFT OUTER JOIN Gecoust f on e.Gk_2 = f.kod
where e.kod like 'SAC SIL%' and f.Evrakno = 'STKGK2'

--
Chandu
Go to Top of Page
   

- Advertisement -