Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Problem with GROUP BY
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

nietzky
Yak Posting Veteran

75 Posts

Posted - 09/13/2013 :  15:42:58  Show Profile  Reply with Quote
I am trying to show the data using this query:
Desired result:
ID_CON Build_PLANNER_SID Build_PLANNER APP_DEV_MANAGER_SID APP_DEV_MANAGER OPS_MANAGER_SID OPS_MANAGER

Query:

select *
from openquery([TEST],

'
SELECT
AC.Construction_ID as ID_CON,
--AC.CONTACTSID as CONTACT_SID,
--AC.CONTACTTYPE as CONTACT_TYPE,
--SYSDATE AS LAST_REFRESHED,
MAX(CASE WHEN AC.CONTACTTYPE = ''Build Planner'' THEN AC.CONTACTSID END) AS Build_PLANNER_SID,
MAX(CASE WHEN AC.CONTACTTYPE = ''Build Planner'' THEN AC.CONTACTTYPE END) AS Build_PLANNER,
MAX(CASE WHEN AC.CONTACTTYPE = ''Construction Development Manager'' THEN AC.CONTACTSID END) AS APP_DEV_MANAGER_SID,
MAX(CASE WHEN AC.CONTACTTYPE = ''Construction Development Manager'' THEN AC.CONTACTTYPE END) AS APP_DEV_MANAGER,
MAX(CASE WHEN AC.CONTACTTYPE = ''OPS Manager'' THEN AC.CONTACTSID END) AS OPS_MANAGER_SID,
MAX(CASE WHEN AC.CONTACTTYPE = ''OPS Manager'' THEN AC.CONTACTTYPE END) AS OPS_MANAGER

FROM DM_PLACE.APP_CONTACTS AC
WHERE AC.CONTACTTYPE = ''Construction Development Manager''
OR AC.CONTACTTYPE = ''Build Planner''
OR AC.CONTACTTYPE =''OPS Manager''
GROUP BY
AC.Construction_ID

')

however I am not getting the same number of records if I just to run the query like this, this query returns more records than the first one, I would think I am going to get the smae number of ID_CONs (unique ones) or even bigger number:




select *
from openquery([TEST],

'
SELECT DISTINCT
AC.Construction_ID as ID_CON,
AC.CONTACTSID as CONTACT_SID,
AC.CONTACTTYPE as CONTACT_TYPE,
SYSDATE AS LAST_REFRESHED

FROM DM_PLACE.APP_CONTACTS AC
WHERE AC.CONTACTTYPE = ''Construction Development Manager''


')


Edited by - nietzky on 09/13/2013 15:47:48

Lamprey
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 09/13/2013 :  15:53:00  Show Profile  Reply with Quote
http://www.sqlservercentral.com/articles/Best+Practices/61537/
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page
  Previous Topic Topic Next 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.06 seconds. Powered By: Snitz Forums 2000