Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

This is my sample data

Name Age Mobile Address DateofLastupdate
------------------------------------------
Baby 1 NULL NULL 2018-07-29
Baby NULL 9999 NULL 2018-07-25
Baby NULL NULL CA 2018-01-01


I Need output with single line from my main table to Temporary table

Name Age Mobile Address DateofLastupdate
------------------------------------------
Baby 1 9999 CA 2018-07-29

What I have tried:

I tried update condition, but its not working, Please suggest any different kind of suggestion
Posted
Updated 29-Jul-18 8:39am
Comments
[no name] 29-Jul-18 7:48am    
Let's see your "update condition not working" before we start looking for "any different kind of suggestion".

1 solution

Try the following select instruction:
SQL
SELECT [NAME], MAX(COALESCE(age,1)) as age, max(coalesce(mobile,'')) as mobile,
   MAX(COALESCE(address,'')) as address, max(COALESCE(dateoflastupdate,'')) as datsoflastupdate
   FROM DATA
   GROUP BY [name]


NOTE In the case that the 'mobile' would be a numeric data change max(coalesce(mobile,'')) with max(coalesce(mobile,0))
 
Share this answer
 
Comments
Naga Sindhura 1-Aug-18 3:18am    
it worked in the way he asked but small suggestion MAX(COALESCE(age,1)) needs to be replaced with MAX(COALESCE(age,0)). I know that that up to the business requirement. What do you think?
Member 7870345 1-Aug-18 16:00pm    
You are ok, MAX(COALESCE(age,1)) it was a mistake.
It must be MAX(COALESCE(age,0))

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900