Link to home
Start Free TrialLog in
Avatar of josereyes
josereyes

asked on

Single select on identical field names without collating conflict ?

OK gurus , listen up....

Have two tables A and B. Want to do a single SELECT if possible that does this

SELECT CASE WHEN A.Code IS NOT NULL THEN A.Code
       ELSE B.Code
GROUP BY A.Code,
         B.Code

This gives a collation error . Also tried COALESCE, also gives collation error.
I am having to do this along with another 20 fields and only suggestion so far is to do a subquery that essentially replicates the main query with the added pain
of giving aliases to several field names.
SQL is very poor !!!
Avatar of egomaster
egomaster

How about:

select ifnull(A.Code,B.Code)
From A,B
Group by A.Code, B.Code

But it feels like some things are missing... For example how A and B should be joined...
ASKER CERTIFIED SOLUTION
Avatar of trouta
trouta

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Brendt Hess
IMO, egomasater is close - use the same IfNull statement in the Group By:

select ifnull(A.Code,B.Code)
From A,B
Group by ifnull(A.Code,B.Code)

Of *course* your actual SQL statement has the join criteria, right?
What is the table structure of tables A and B (ie the data types of the field CODE?
What is some sample data and what the expected result?
Correct. isnull and not ifnull...
Here's a horrible thought. What if the two tables are from two different databases that have different collation sequences? Also, note that if A.Code and B.Code have different data types then the data type with the higher precedence wins (see Data Type Precedence in T-SQL help).
Avatar of josereyes

ASKER

Trouta first on starting line, thanks very much...
Jose
josereyes,

These questions are still open and our records show you logged in recently. Please resolve them appropriately as soon as possible. Continued disregard of your open questions will result in the force/acceptance of a comment as an answer; other actions affecting your account may also be taken. I will revisit these questions in approximately seven (7) days.
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11324697
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11723798
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20164448
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20165555
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20173349
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20187667
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20193216

EXPERTS: Please leave your thoughts on this question here.

Thanks,

Netminder
Community Support Moderator
Experts Exchange
Admin notified of user neglect. Force/accepted by

Netminder
Community Support Moderator
Experts Exchange