🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: bit.databases.mssql-l
Article #1

Re: query??

#1
From: Jens Smeyer
Date: Wed, 03 Sep 2003 05:59
74 lines
2971 bytes
you have to put the strigs all together, bute till you don�t post some ddl
and exmplae data its not very easy to help you. The first thing, is to do
this query with a function that concas these values together:

---Untested, because of missing examples:

DROP Function fn_Myfunc

CREATE FUNCTION fn_Myfunc(@COL int)
RETURNS VARCHAR(30)
AS
BEGIN
 DECLARE @W VARCHAR(30)
 DECLARE @EXAM varchar(50)
 SET @W = ''
 SELECT @W = @W + CAST(examname AS VARCHAR(10)) + ' ' FROM temptable  WHERE
studentID=@COL
 SELECT @EXAM=examname FROM temptable WHERE studentID=@COL
 If @EXAM IS NOT NULL
 BEGIN
   SET @W = LEFT(@W,LEN(@W)-1)
 END
 RETURN @W
END
GO

SELECT StudentID,[P/F],dbo.fn_Myfunc(StudentID) as Exams
FROM temptable

But for this, tables must be non temporary, because of working in a
function.

HTH, Jens S��meyer.



"ricksql@yahoo.com" <u50415039@spawnkill.ip-mobilphone.net> schrieb im
Newsbeitrag news:l.1062563763.1400665283@host-66-81-69-23.rev.o1.com...
> #temptable (studentID,p/f,examid,examname):
> 1   p
> 2   f    100  bio
> 2   f    101  mTH
> 2   f    102  CHM
> 2   f    103  spts
> 2   f    104  LIT
> 2   f    107  geo
> 2   f    109  phys
> 2   f    110  eng
> 2   f    111  hist
> 3   p
> 4   f    100  bio
> 4   f    102  chm
> 4   f    109  phys
> 4   f    110  eng
>
> #tempResult:
>
> (studentid,p/f,1st,2st,3rd,4th,5th)
> 1  p
> 2  f   bio  math  chm  spts  lit
> 3  p
> 4  f   bio  chm  phys  eng
>
>
> what query turns #temptable to #tempresult?.
> rick
>
>
>
>
> --
> Sent  by  ricksql from yahoo in field com
> This is a spam protected message. Please answer with reference header.
> Posted via http://www.usenet-replayer.com/cgi/content/new
Technical Details
Message-ID: <#e36Z#dcDHA.4020@tk2msftngp13.phx.gbl>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!t-online.de!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
References: <l.1062563763.1400665283@host-66-81-69-23.rev.o1.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 11301e,491a6121cd5fc1c6
X-Google-Attributes: gid11301e,public
X-Google-Thread: f6611,491a6121cd5fc1c6
X-Google-Attributes: gidf6611,public
X-Google-Thread: 104de1,491a6121cd5fc1c6
X-Google-Attributes: gid104de1,public
X-Google-Thread: 107d2f,491a6121cd5fc1c6
X-Google-Attributes: gid107d2f,public
X-Google-ArrivalTime: 2003-09-02 22:54:51 PST
From: "Jens S��meyer" <jsuessmeyer@(Remove_ME]web.de>
References: <l.1062563763.1400665283@host-66-81-69-23.rev.o1.com>
Subject: Re: query??
Date: Wed, 3 Sep 2003 07:59:06 +0200
Lines: 76
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Message-ID: <#e36Z#dcDHA.4020@tk2msftngp13.phx.gbl>
Newsgroups: bit.databases.mssql-l,comp.databases.ms-sqlserver,microsoft.public.sqlserver,microsoft.public.sqlserver.programming
NNTP-Posting-Host: pd9eac5d4.dip0.t-ipconnect.de 217.234.197.212
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!t-online.de!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl