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
 General SQL Server Forums
 New to SQL Server Programming
 Dynamic sql

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-08-15 : 07:37:55
Anitha writes "I am just a beginner and i need help to solve the below problem in sql


I have 6 records in info table


name id phone
ani 1 999-980-234
ani 1 999-980-145
ani 1 999-980-913

bav 2 888-000-999
bav 2 888-000-991


I want it to be into one record

name id phone1 phone2 phone3
ani 1 999-980-234 999-980-145 999-980-913
bav 2 888-000-999 888-000-991



I want my sql to dynamically create columns and append data
I an do it by assigning the values individually .. which is really tedious .

Appreciate it if you could help me .
Thank you ,
Anitha"

timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2005-08-15 : 07:43:12
You're referring to what is sometimes known as a crosstab query. It's usually used to display totals and stuff like that (ie aggregates), but not normally to do this sort of thing. It might get quite ugly.
Is the number of phone numbers a person can have fixed?

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-16 : 01:19:30
Refer this
http://sqljunkies.com/WebLog/amachanic/archive/2004/11/10/5065.aspx?Pending=true

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -