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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to make this query ?

Author  Topic 

hdv212
Posting Yak Master

140 Posts

Posted - 2010-12-27 : 12:38:55
Hi
suppose we have a table with this type of data :

id name family age
xx1 null null null
null xxx xxx xxx
xx2 null null null
null xxx xxx xxx
null xxx xxx xxx
...

as u can see, i have a record which have only id value and some records which have rest of columns value (except of id)
i want to merge record which have id value with next rows which does not have id value while it reach to next row which have id value, something like this :

id name family age
xx1 xxx xxx xxx
xx2 xxx xxx xxx
xx2 xxx xxx xxx
...

can anybody help me which how to accomplish this ?
thanks in advance

X002548
Not Just a Number

15586 Posts

Posted - 2010-12-27 : 12:46:09
do you understand that there is no inherent relationship between rows of data unless it's defined as a hierarchy?

Do you have such a definitions in your database table?

It doesn't look like it.

You meed to think in set based logic

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-12-27 : 13:04:26
Is there a column or combination of columns that you can use to determine the order of the rows? I.E. - What ORDER BY clause would you need in order to get the results of your table in the order you specified?

SELECT Id, Name, Family, Age
FROM MyTable
ORDER BY ???

To prodcue:
id name family age
xx1 null null null
null xxx xxx xxx
xx2 null null null
null xxx xxx xxx
null xxx xxx xxx
...
Go to Top of Page

hdv212
Posting Yak Master

140 Posts

Posted - 2010-12-27 : 13:10:32
i know this, but actually, this is not table, it is excel report of another application which i imported it to sql server, because i need a result as i described in my first post.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-12-28 : 01:28:15
So if your excel sheet is ordered as you need then you should add a rownumber before importing into a database table.



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -