SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 Subquery as Column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Kelapa
Starting Member

Turkey
8 Posts

Posted - 04/12/2013 :  03:43:23  Show Profile  Reply with Quote
What am I doing wrong?

bandi
Flowing Fount of Yak Knowledge

India
2217 Posts

Posted - 04/12/2013 :  03:48:38  Show Profile  Reply with Quote
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

Turkey
8 Posts

Posted - 04/12/2013 :  04:11:40  Show Profile  Reply with Quote
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

Turkey
8 Posts

Posted - 04/12/2013 :  04:26:22  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
2217 Posts

Posted - 04/12/2013 :  04:36:50  Show Profile  Reply with Quote
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

Edited by - bandi on 04/12/2013 04:37:12
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2217 Posts

Posted - 04/12/2013 :  04:49:32  Show Profile  Reply with Quote
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

Turkey
8 Posts

Posted - 04/12/2013 :  04:58:12  Show Profile  Reply with Quote
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

Edited by - Kelapa on 04/12/2013 04:58:57
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2217 Posts

Posted - 04/12/2013 :  05:40:35  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000