Avatar of keplan
keplanFlag for Australia

asked on 

How to get the non null values in a row sets to one row usin t-sql 2008

my excel data set like below, I need to get the resut as I shown below:

Excel Source:
Col1 Col2 Col3 Col4 Col5 Col6  col7
1       abc   tt     null   88   9      null
1       abc   tt     2      null  null   null
1       abc   tt      null  null  null  null

my expected Result:

col1 col2 col3  col4 col5 col6  col7
1     abc   tt     2     88    9     null


Can anybody suggest solution to this?

Microsoft SQL Server 2008

Avatar of undefined
Last Comment
keplan
Avatar of el_aristo
el_aristo

you can use max method
select MAX(col1) , MAX(col2), MAX(col3),  MAX(col4), MAX(col5) ,MAX(col6)  ,MAX(col7)
Avatar of ksparky
ksparky
Flag of United States of America image

Select Max(col1) col1, Max(col2) col2, Max(col3) col3, Max(col4) col4, Max(col5) col5, Max(col6) col6, Max(col7) col7 FROM <tablename>
Avatar of keplan
keplan
Flag of Australia image

ASKER

thanks for all those gave me some sort of solution:
sorry for the not mentioned this bit ealier: i've added the new data into my source:

Excel Source:
Col1 Col2 Col3 Col4 Col5 Col6  col7
1       abc   tt     null   88   9      null
1       abc   tt     2      null  null   null
1       abc   tt      null  null  null  null
3       fgt    hh    null   3      null  null
3      fgt     hh    2      null   1      null
4      kkl    jj       null  8      3       1
4      kkl    jj      3     null    null   null

so as the data set, the col1, col2, col3 need to eliminated it duplicates, as below result:

col1   col2  col3 col4  col5  col6  col7
1       abc   tt     2      3       9      null
3       fgt    hh    2      3       1     null
4      kkl    jj      3       8      3       1

please give me solution to this
thanks in advance




Avatar of Sharath S
Sharath S
Flag of United States of America image

try this.
SELECT col1, 
         MAX(col2) col2, 
         MAX(col3) col3, 
         MAX(col4) col4, 
         MAX(col5) col5, 
         MAX(col6) col6, 
         MAX(col7) col7 
    FROM your_table 
GROUP BY col1; 

Open in new window

Avatar of ksparky
ksparky
Flag of United States of America image

Select Max(col1) col1, Max(col2) col2, Max(col3) col3, Max(col4) col4, Max(col5) col5, Max(col6) col6, Max(col7) col7 FROM <tablename>
GROUP BY col1
ASKER CERTIFIED SOLUTION
Avatar of el_aristo
el_aristo

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of keplan
keplan
Flag of Australia image

ASKER

solve the problem partially
Microsoft SQL Server 2008
Microsoft SQL Server 2008

Microsoft SQL Server 2008 is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning. Major improvements include the Always On technologies and support for unstructured data types.

50K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo