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
 New to SQL Server Programming
 how to apply EXISTS here?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

barnabeck
Posting Yak Master

Spain
201 Posts

Posted - 09/26/2013 :  05:02:21  Show Profile  Reply with Quote
I have this Query:
select WS_CONTRACTORCUSTOMER,
      SALESLINE.SALESSTATUS,
      SUM(CASE WHEN SALESLINE.SALESSTATUS =1 THEN REMAINSALESPHYSICAL ELSE REMAINSALESFINANCIAL END * SALESLINE.SALESPRICE) as total
from SALESLINE
	left outer join SALESTABLE ON SALESLINE.SALESID = SALESTABLE.SALESID and SALESTABLE.DATAAREAID ='ES75'
      left outer join INVENTTABLE on SALESLINE.ITEMID = INVENTTABLE.ITEMID and INVENTTABLE.DATAAREAID ='ES75'
where SALESLINE.DATAAREAID ='ES75' and 
      (SALESLINE.SALESSTATUS =1 OR SALESLINE.SALESSTATUS =2) and 
      (SALESLINE.SALESTYPE =3 OR SALESLINE.SALESTYPE = 4) and 
      (SalesTable.ReturnStatus = 3 OR ISNULL(SalesTable.ReturnStatus,0) = 0) and 
      WK_SalesVariant <> 5 and 
      (ItemGroupID LIKE 'I%' OR ItemGroupID = 'SV-CERT' OR ItemGroupID = 'SV-SERV') and 
      SALESLINE.SHIPPINGDATECONFIRMED <= GETDATE()
GROUP BY WS_CONTRACTORCUSTOMER, SALESLINE.SALESSTATUS
ORDER BY WS_CONTRACTORCUSTOMER, SALESLINE.SALESSTATUS


Now I need to substitute the reference-date GETDATE() with the date returned by this query:
select TOP 1 Invoicedate, COUNT (INVOICEDATE) as cnt 
from (select TOP 600 INVOICEDATE
      from CUSTINVOICETRANS
      where DATAAREAID = 'ES75' and Invoicedate <= '2013-07-29'
      ORDER BY INVOICEDATE desc)a
GROUP BY INVOICEDATE
ORDER BY cnt desc


If I do it by just wrapping the query into brackets I get this error message: Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.. I was trying that but don't succeed, cause I never used EXISTS in such a context.

Martin

Edited by - barnabeck on 09/26/2013 05:04:40

barnabeck
Posting Yak Master

Spain
201 Posts

Posted - 09/26/2013 :  05:08:17  Show Profile  Reply with Quote
OK... my fault. I just saw that my inner query returns two columns...
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