Click here to Skip to main content
12,633,079 members (34,223 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: SQL-Server
I have example:
SELECT 1 AS ID, 'a' AS NAME1, null AS NAME2
UNION
SELECT 1 AS ID, 'a' AS NAME1, 'b' AS NAME2

Result:

ID NAME1 NAME2
1 a null
1 a b

How can it combined ?

ID NAME1 NAME2
1 a b
Posted 14-Nov-12 5:53am
Updated 14-Nov-12 6:22am
RaisKazi34.5K
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

you can't. You did a union asking for the null value, so you have it. I don't know what you mean by 'combined', but you are selecting the same thing as NAME1 in both cases, so there's nothing to combine. You're getting exactly what you asked for, and based on your question, there's nothing else you could want, apart from removing the union
  Permalink  
Comments
RaisKazi 14-Nov-12 11:25am
   
My 5. Exactly, question makes no sense. OP ordered Coffee-Mocha and shouting why I am getting Chi-Latte. :)))
Christian Graus 14-Nov-12 11:26am
   
More correctly, he ordered a mocha, and shouted 'there's chocolate in my coffee !!' :P
RaisKazi 14-Nov-12 11:28am
   
:))

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 14 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100