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
 Other Forums
 Other Topics
 Different results from the same query...

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-07-21 : 09:43:28
BRYAN writes "Hello.. I work in an environment with 2 separate regions (prod and test). I have a SQL query that runs perfectly in prod and gives different results in test. Here is the SQL query:

(SELECT TERMINAL_ID AS CCID,
AUDIT_STATUS_CODE AS AUDCODE,
'M' AS AUDTYPE,
COUNT(*) AS AUDCNT
FROM CUSTOMER_MASK A
, CUSTOMER_PROFILE B
WHERE FK_CUSTOMER_NUMBER = CUSTOMER_NUMBER
AND (B.CARRIER_SCAC_CD = ' ' OR
B.CARRIER_SCAC_CD = 'ARFW')
GROUP BY TERMINAL_ID,
AUDIT_STATUS_CODE
UNION ALL
SELECT TERMINAL_ID AS AUDUSER,
AUDIT_STATUS_CODE AS AUDCODE,
'I' AS AUDTYPE,
COUNT(*) AS AUDCNT
FROM CUSTOMER_ITEM A
, CUSTOMER_PROFILE B
WHERE FK_CUSTOMER_NUMBER = CUSTOMER_NUMBER
AND (B.CARRIER_SCAC_CD = ' ' OR
B.CARRIER_SCAC_CD = 'ARFW')
GROUP BY TERMINAL_ID,
AUDIT_STATUS_CODE
FOR FETCH ONLY);


When we run this in Prod, we get 4 colums: CCID, AUDCODE, AUDTYPE and AUDCNT.

When we run this in test, we get 4 colums: col1, AUDCODE, AUDTYPE and AUDCNT.

Because we get col1 instead of CCID for or column heading, our program is abending later down the line.

I see that the problem is caused by the field TERMINAL_ID having 2 different names (CCID and AUDUSER). We are trying to figure out why we are getting different results for the same query? (By the way, prod and test has the same data in the DB2 tables.)

Thanks,
Bryan N."

nr
SQLTeam MVY

12543 Posts

Posted - 2006-07-21 : 10:33:45
Are they the same version and service pack? Changes were made in this area for v2005 - don't know about service packs for v2000.

Try select @@version on both servers.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2006-07-21 : 11:06:52
"Are they the same version and service pack? Changes were made in this area for v2005 - don't know about service packs for v2000.

this might conflict with the user statement....

...By the way, prod and test has the same data in the DB2 tables."


But the solution is easy....make the "as" field names the same on both sides of the UNION statement.
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2006-07-21 : 11:39:22
Oops.
Should look at which forum a post is in occasionally.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -