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
 split function

Author  Topic 

rameshsri
Starting Member

2 Posts

Posted - 2011-07-05 : 08:46:42
Hi,
I am creating one table and insert some values it means like

Techer Table

Id TeacherName DeptId Deptname
1 gokul 1,2 CSE,EEE
2 Sathish 1,2,3 CSE,ECE,IT

I want write one store procedure it means in where condition i want to give the id is 2 and deptid is 2 means
it will fetch the information like

Id TeacherName DeptId Deptname
2 Sathish 2 ECE


U don't know how to fetch that i need help




Ramesh Srinivasan

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-07-05 : 08:55:33
Your problem is a messy table - don't do that.


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

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2011-07-05 : 08:59:34
See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033

SELECT *, dbo.fnParseString(-2, ',', DeptName)
FROM Teacher
WHERE ID = 2



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2011-07-05 : 15:02:08
Webfred is correct in that your data structure is flawed. Here is a link that might get you started on how to normalize you data:
http://en.wikipedia.org/wiki/Database_normalization
Go to Top of Page

pduffin
Yak Posting Veteran

68 Posts

Posted - 2011-07-05 : 19:54:44
This is a one to many relationship so a cross reference table is needed here if you ever want to be able to re-associate a teacher to a dept without loads of unnecessary code.
Go to Top of Page

pduffin
Yak Posting Veteran

68 Posts

Posted - 2011-07-05 : 19:55:26
Look up 3rd normal form 3NF.
Go to Top of Page
   

- Advertisement -