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.
| Author |
Topic |
|
jgsteeler
Starting Member
12 Posts |
Posted - 2004-02-03 : 09:28:21
|
| I am writing a Report Query using SQL. I have set up a temp table with ID's and Address information . I need to add a column to the Temp table that will have a string with all of the Certifications for each ID in the temp table. The certifications are in anothe table. I declared another table to get all of the certifications for each ID in the Main table. Some of the ID's have more than one Cert. How can I concatanate all of the certs for each ID in to one string and put that string into the main table? I know that I can use cursor but I don't like them and they make the query run slow. I am new to SQL programming so if the solution is simple forgive me. Thanks |
|
|
jgsteeler
Starting Member
12 Posts |
Posted - 2004-02-03 : 09:39:02
|
| Here is the code I am currently usingDECLARE @TEMP TABLe (FACID int, FACNAME VARCHAR(75), CERTTYPE NVARCHAR(4000))INSERT @TEMPSELECT intFacilityID, txtFacilityName, NUllfrom tblproviderFacility FACDECLARE FCRS Cursor DYNAMICFOR SELECT FACID from @TEMPFOR UPDATEDECLARE @FID intOPEN FCRSFETCH NEXT From FCRS into @FIDWHILE @@FETCH_STATUS=0BEGINDECLARE CERT CURSOR FORSELECT Distinct PCERT.intCertificationID,txtCertificationname,Ct.intCertificationTypeID,txtCertificationTypenamefrom tblproviderFacility_Certifications PCERT INNER JOIN tblCertification CRT on CRT.intCertificationID=PCERT.intCertificationId INNER JOIN XtblCertificationTypes CT on Ct.intCertificationTypeID=CRT.intCertificationTypeID Where intFacilityID=@fidDECLARE @CID int, @CNAME VARCHAR(75), @CTYPE int, @CTYPENAME VARCHAR(75)DECLARE @CERT NVARCHAR(4000)Set @cert=nullOPEN CERTFETCH NEXT FROM CERT into @CID,@CNAME,@CTYPE,@CTYPENAMEWHIlE @@FETCH_STATUS=0BEGIN IF @CERT IS NOT NULL BEGIN SET @CERT=ISNULL(@CERT,'')+SPACE(1)+ISNULL(@CNAME+SPACE(1)+@CTYPENAME,'') END IF @CERT IS NULL BEGIN SET @CERT=ISNULL(@CERT,'')+ISNULL(@CNAME+SPACE(1)+@CTYPENAME,'') ENDFETCH NEXT FROM CERT into @CID,@CNAME,@CTYPE,@CTYPENAMEENDCLOSE CERTDEALLOCATE CERTUPDATE @TEMP Set CERTTYPE=@CERTWhere CUrrent of FCRSFETCH NEXT from FCRS into @FIDENDCLOSE FCRSDEALLOCATE FCRS SELECT * from @TEMPwhere certtype is not null Order by FACIDAlways look on the bright side of life, ta dum, ta dum.Monthy Python, The Life of Brian |
 |
|
|
AndrewMurphy
Master Smack Fu Yak Hacker
2916 Posts |
Posted - 2004-02-03 : 09:49:23
|
| search here for csv..."comma seperated variables"....this topic comes up a lot.You need a cursor like you need a gunshot hole in the head. |
 |
|
|
jgsteeler
Starting Member
12 Posts |
Posted - 2004-02-03 : 09:59:43
|
| Thanks That CSV stuff helpedAlways look on the bright side of life, ta dum, ta dum.Monthy Python, The Life of Brian |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-02-03 : 15:46:50
|
quote: Originally posted by AndrewMurphy need a cursor like you need a gunshot hole in the head.
PULL![booooooom]CURSOR[/booooooom]Brett8-) |
 |
|
|
|
|
|
|
|