Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Urgent development question Expand / Collapse
Author
Message
Posted Monday, January 25, 2010 9:53 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, April 30, 2013 7:10 AM
Points: 322, Visits: 368
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.
Post #853117
Posted Monday, January 25, 2010 10:07 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 4:30 AM
Points: 37,742, Visits: 30,021
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 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #853137
Posted Monday, January 25, 2010 10:21 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Yesterday @ 3:30 PM
Points: 31,436, Visits: 13,751
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.








Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #853153
Posted Monday, January 25, 2010 10:24 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, April 30, 2013 7:10 AM
Points: 322, Visits: 368
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...
Post #853155
Posted Monday, January 25, 2010 10:30 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 10:25 AM
Points: 18,754, Visits: 12,337
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
http://www.sqlservercentral.com/Forums/Topic845680-338-1.aspx





Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server 2008


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #853160
Posted Monday, January 25, 2010 10:39 AM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Tuesday, August 02, 2011 3:36 AM
Points: 579, Visits: 1,803
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


---------------------------------------------------------------------------------
Post #853168
Posted Monday, January 25, 2010 11:18 AM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Yesterday @ 10:09 AM
Points: 789, Visits: 5,198
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
Post #853188
Posted Monday, January 25, 2010 12:03 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 4:30 AM
Points: 37,742, Visits: 30,021
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 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #853213
Posted Monday, January 25, 2010 12:47 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 10:25 AM
Points: 18,754, Visits: 12,337
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 2008


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #853242
Posted Monday, January 25, 2010 1:36 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Tuesday, May 21, 2013 1:55 PM
Points: 15,442, Visits: 9,571
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
Post #853282
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse