January 25, 2010 at 9:53 am
urgent development question:
i have a table which contains following columns:
name,
student id,
subjects
in subjects column we have subjects taken by each student seperated by semicolumn.i.e. "english;social study;crafts" etc.
now, curre, I want output table which is seperated by each subject...i.e.
before
------
name | student id | subjects
stdA| 123| english;social study
stdB| 234| social study;crafts
After
-----
name | student id | subjects
stdA| 123| english
stdA| 123| social study
stdB| 234| social study
stdB| 234| social crafts
....
Please help me as this is urgent.
Thanks.
January 25, 2010 at 10:07 am
Why is this urgent? Homework with an upcoming deadline?
Please post table definitions, sample data and desired output. Read this to see the best way to post this to get quick responses.
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
January 25, 2010 at 10:21 am
We don't do homework questions. We are happy to help you figure things you, but you need to make an attempt to get some initial work done and show some code you've written.
January 25, 2010 at 10:24 am
I didn't submitted the correct data as I don't want to send company data out...Next time I will make sure to put question in right format...sorry this time...Plz let me know if anyone has any idea...Thanks in advance...
January 25, 2010 at 10:30 am
Here is a thread that may help you find your solution. You will still need to look at the code and determine how to adapt it to your situation. Thus no direct code answer, but an answer as to how to find your answer:-D
http://www.sqlservercentral.com/Forums/Topic845680-338-1.aspx
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
January 25, 2010 at 10:39 am
RPSql (1/25/2010)
I didn't submitted the correct data as I don't want to send company data out...Next time I will make sure to put question in right format...sorry this time...Plz let me know if anyone has any idea...Thanks in advance...
Even the same data that you posted would do but in a consumable format as suggested by Gail 🙂
---------------------------------------------------------------------------------
January 25, 2010 at 11:18 am
Just a thought...
If this is development, you may want to review the design.
Having a table for Subject ( with just a Code and Description for each Subject ) might allow you to more naturally get to the results you are seeking.
Say data was populated from a web form, would you have a drop down with every available combination of subects? Or allow freeform text to be entered? And then how would you validate user input?
Greg E
January 25, 2010 at 12:03 pm
Greg Edwards-268690 (1/25/2010)
Just a thought...If this is development, you may want to review the design.
Absolutely. Comma-delimited lists in a column are a violation of 1st Normal Form and are an absolute pain to deal with. This is the easy part, trying to add or remove 'subjects' from the list is far harder.
Take the time to properly normalise the table, and you won't have problems like this one.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
January 25, 2010 at 12:47 pm
GilaMonster (1/25/2010)
Greg Edwards-268690 (1/25/2010)
Just a thought...If this is development, you may want to review the design.
Absolutely. Comma-delimited lists in a column are a violation of 1st Normal Form and are an absolute pain to deal with. This is the easy part, trying to add or remove 'subjects' from the list is far harder.
Take the time to properly normalise the table, and you won't have problems like this one.
Taking it a step further - normalize any tables that have any (comma,semi-colon, etc) delimited columns
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
January 25, 2010 at 1:37 pm
GilaMonster (1/25/2010)
Greg Edwards-268690 (1/25/2010)
Just a thought...If this is development, you may want to review the design.
Absolutely. Comma-delimited lists in a column are a violation of 1st Normal Form and are an absolute pain to deal with. This is the easy part, trying to add or remove 'subjects' from the list is far harder.
Take the time to properly normalise the table, and you won't have problems like this one.
Even worse is if a subject needs to be renamed. What if "English" becomes "Language Arts" (as it did for me while I was in high school)? Can't just simply "replace" it, because you could also have a class on "Advanced English Literature", or "English as a Second Language", and suddenly you'd mess those up. Can become quite tricky.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
January 25, 2010 at 1:54 pm
GSquared (1/25/2010)
GilaMonster (1/25/2010)
Greg Edwards-268690 (1/25/2010)
Just a thought...If this is development, you may want to review the design.
Absolutely. Comma-delimited lists in a column are a violation of 1st Normal Form and are an absolute pain to deal with. This is the easy part, trying to add or remove 'subjects' from the list is far harder.
Take the time to properly normalise the table, and you won't have problems like this one.
Even worse is if a subject needs to be renamed. What if "English" becomes "Language Arts" (as it did for me while I was in high school)? Can't just simply "replace" it, because you could also have a class on "Advanced English Literature", or "English as a Second Language", and suddenly you'd mess those up. Can become quite tricky.
Exactly why we always have the code on the fact record, and have a reference table with code and description. Descriptions tend to change over time for a number of reasons, and updating millions of fact records vs. 1 reference table is much easier.
A couple of these tips should prove very valuable.
GE
January 25, 2010 at 2:33 pm
CirquedeSQLeil (1/25/2010)
Here is a thread that may help you find your solution. You will still need to look at the code and determine how to adapt it to your situation. Thus no direct code answer, but an answer as to how to find your answer:-Dhttp://www.sqlservercentral.com/Forums/Topic845680-338-1.aspx
Ahh yes, I remember this thread. It was fun, and it would definitely guide the OP on a solution for his problem.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
January 25, 2010 at 5:39 pm
WayneS (1/25/2010)
CirquedeSQLeil (1/25/2010)
Here is a thread that may help you find your solution. You will still need to look at the code and determine how to adapt it to your situation. Thus no direct code answer, but an answer as to how to find your answer:-Dhttp://www.sqlservercentral.com/Forums/Topic845680-338-1.aspx
Ahh yes, I remember this thread. It was fun, and it would definitely guide the OP on a solution for his problem.
That was an awesome thread. You guys had a lot of fun on that one.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 25, 2010 at 7:03 pm
Jeff Moden (1/25/2010)
WayneS (1/25/2010)
CirquedeSQLeil (1/25/2010)
Here is a thread that may help you find your solution. You will still need to look at the code and determine how to adapt it to your situation. Thus no direct code answer, but an answer as to how to find your answer:-Dhttp://www.sqlservercentral.com/Forums/Topic845680-338-1.aspx
Ahh yes, I remember this thread. It was fun, and it would definitely guide the OP on a solution for his problem.
That was an awesome thread. You guys had a lot of fun on that one.
Yes yes - good thread it was.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
Viewing 14 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply