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
 How to create two separate fields from the data?

Author  Topic 

sqlteamForummer
Starting Member

13 Posts

Posted - 2007-08-02 : 10:43:59
Can anyone please help me with the following:


I have a table which has fields called defid, datavalue, pid etc.
I have to create a new table which should have fields:
CustID, datavalue[SocSec]{note:this is the value in d.datavalue when defid is 1004), datavalue[FirstName]{note: this is the value in d.datavalue when defid is 1006}, datavalue[LastName]{note: this is the value in d.datavalue when defid is 1007}, [FullName] {note: this is the value I should get by joining the datavalues (lastname and firstname) when defifis 1006 and 1007) ie. ex: FirstNameLastName.

COULD ANYONE PLEASE HELP ME ON THIS. DATA QUERY is as follows:
Thank you in advance.

SELECT DISTINCT c.CustID, d.datavalue, f.name
FROM dbo.Customers c
INNER JOIN dbo.Date7 d ON d.pid = c.root
INNER JOIN dbo.fielddisc f ON f.defid = d.defid
WHERE c.separatedate BETWEEN @StartDate AND @EndDate
AND c.DateTab = 7 AND d.defid IN (1004, 1006, 1007, 1009) AND c.CustID = 10 AND c.root = 8472
ORDER BY c.root

X002548
Not Just a Number

15586 Posts

Posted - 2007-08-02 : 10:46:55
maybe you can supply some sample Data

Read the hint link in my sig and post what it asks for



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

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-08-02 : 10:53:16
it looks like you're trying to do horizontal partitioning.
http://www.sqlteam.com/article/partitioning-the-data-in-a-table

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

sqlteamForummer
Starting Member

13 Posts

Posted - 2007-08-02 : 11:17:48
Sample Data is:

Data for the table which has fields called defid, datavalue, pid etc.
NOTE: the order for the data may not be the same


pid defid datavalue

8472 1004 500-324-1444 {note: SocSec}
8472 1006 Andrew {note: FirstName}
8472 1007 McCormick {note: LastName}
8472 1009 California {note: State}

2552 1009 Newyork {note: State}
2552 1006 Fred {note: FirstName}
2552 1004 255-753-6936 {note: SocSec}
2552 1007 Dawson {note: LastName}



-----------------------------------------
Data for the new table should look like

CustID SocSec FirstName LastName FirstNameLastName


Go to Top of Page
   

- Advertisement -