Click here to Skip to main content
16,004,901 members
Home / Discussions / Database
   

Database

 
GeneralRe: sql query proble Pin
RajeevKumarSharma30-Jan-08 22:20
RajeevKumarSharma30-Jan-08 22:20 
GeneralReg:Auto Shrink Database [modified] Pin
P.T.R.K30-Jan-08 18:58
P.T.R.K30-Jan-08 18:58 
Generalimport data from excel spreadsheet into sql database Pin
solarthur0130-Jan-08 13:28
solarthur0130-Jan-08 13:28 
GeneralRe: import data from excel spreadsheet into sql database Pin
pmarfleet30-Jan-08 21:29
pmarfleet30-Jan-08 21:29 
GeneralRe: import data from excel spreadsheet into sql database Pin
John_Adams30-Jan-08 22:08
John_Adams30-Jan-08 22:08 
GeneralReturn Child rows as a concatenated string Pin
AlexeiXX330-Jan-08 13:01
AlexeiXX330-Jan-08 13:01 
GeneralRe: Return Child rows as a concatenated string Pin
pmarfleet30-Jan-08 21:27
pmarfleet30-Jan-08 21:27 
AnswerRe: Return Child rows as a concatenated string Pin
Ashfield31-Jan-08 2:42
Ashfield31-Jan-08 2:42 
Alexei

Try this:

/* create tables for examples */<br />
create table student (StudentID int, Name varchar(50))<br />
create table student_course (StudentID int, CourseID int)<br />
create table course (CourseID int, Name varchar(50))<br />
<br />
insert into student select 1,'Fred'<br />
insert into student select 2,'Joe'<br />
insert into student select 3,'Mary'<br />
<br />
insert into course select 1,'Maths'<br />
insert into course select 2,'Cooking'<br />
insert into course select 3,'Languages'<br />
<br />
insert into student_course select 1,1<br />
insert into student_course select 1,3<br />
insert into student_course select 2,1<br />
insert into student_course select 3,1<br />
insert into student_course select 3,2<br />
insert into student_course select 3,3<br />
<br />
go<br />
<br />
/* the bit that really does the work */<br />
CREATE FUNCTION dbo.udf_GetStudentCourses(@StudentID int)<br />
RETURNS VARCHAR(1000) AS<br />
<br />
BEGIN<br />
   DECLARE @CourseList varchar(1000)<br />
<br />
   SELECT @CourseList = COALESCE(@CourseList + ', ', '') + c.Name<br />
   FROM Student_Course s, Course c<br />
   WHERE s.StudentID = @StudentID<br />
	and c.CourseID = s.CourseID<br />
<br />
   RETURN @CourseList<br />
END<br />
go<br />
<br />
/* get the results */<br />
select Name,dbo.udf_GetStudentCourses(StudentID)<br />
from Student


Results:


Fred Maths, Languages
Joe Maths
Mary Maths, Cooking, Languages


Bob
Ashfield Consultants Ltd

GeneralRe: Return Child rows as a concatenated string Pin
AlexeiXX331-Jan-08 8:37
AlexeiXX331-Jan-08 8:37 
QuestionStarting a new transaction thead after it ends quickly (like would do an ISR, Interupt Service Routine) Pin
grozo30-Jan-08 11:41
grozo30-Jan-08 11:41 
GeneralRe: Starting a new transaction thead after it ends quickly (like would do an ISR, Interupt Service Routine) Pin
PIEBALDconsult30-Jan-08 13:07
mvePIEBALDconsult30-Jan-08 13:07 
GeneralRe: Starting a new transaction thead after it ends quickly (like would do an ISR, Interupt Service Routine) Pin
grozo6-Feb-08 19:25
grozo6-Feb-08 19:25 
GeneralSelect statement using strig column as parameter Pin
AlexeiXX330-Jan-08 8:02
AlexeiXX330-Jan-08 8:02 
GeneralRe: Select statement using strig column as parameter Pin
pmarfleet30-Jan-08 8:18
pmarfleet30-Jan-08 8:18 
GeneralRe: Select statement using strig column as parameter Pin
AlexeiXX330-Jan-08 12:47
AlexeiXX330-Jan-08 12:47 
GeneralRe: Select statement using strig column as parameter Pin
pmarfleet30-Jan-08 21:25
pmarfleet30-Jan-08 21:25 
QuestionWhy is Oracle OLE wizard trying to open SQL Server? Pin
Richard Jones30-Jan-08 4:31
Richard Jones30-Jan-08 4:31 
QuestionHow to Display and Save the SQl Database Diagrams or Schemma in SQL 2000 Pin
Vimalsoft(Pty) Ltd30-Jan-08 2:54
professionalVimalsoft(Pty) Ltd30-Jan-08 2:54 
AnswerRe: How to Display and Save the SQl Database Diagrams or Schemma in SQL 2000 Pin
AlexeiXX330-Jan-08 8:04
AlexeiXX330-Jan-08 8:04 
GeneralHelp with MS SQL Update statement please. Pin
Steven J Jowett30-Jan-08 2:03
Steven J Jowett30-Jan-08 2:03 
GeneralRe: Help with MS SQL Update statement please. Pin
Steven J Jowett30-Jan-08 2:18
Steven J Jowett30-Jan-08 2:18 
GeneralRe: Help with MS SQL Update statement please. Pin
Ashfield30-Jan-08 2:21
Ashfield30-Jan-08 2:21 
GeneralRe: Help with MS SQL Update statement please. Pin
Steven J Jowett30-Jan-08 5:21
Steven J Jowett30-Jan-08 5:21 
GeneralRe: Help with MS SQL Update statement please. Pin
Ashfield30-Jan-08 7:22
Ashfield30-Jan-08 7:22 
QuestionHow Can I execute pl/sql query?? Pin
Vanamaindia29-Jan-08 23:09
Vanamaindia29-Jan-08 23:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.