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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Stored Procedure

Author  Topic 

jpcraw
Starting Member

3 Posts

Posted - 2008-03-27 : 16:11:37
Here is my SP.



/*********************************************************************************************************
* Type : Procedure
* Name : spGetCourseEmailList
* Input Parameters : @Code1
* Output Parameters : None
* Purpose : This stored procedure gets the Members for a particular Chapter Event the cached items.
**********************************************************************************************************/
CREATE PROCEDURE [dbo].[spGetCourseEmailList]
(
@Code1 char(9)
)
AS

SELECT dbo.[names].lname as LastName,
dbo.[names].fname as FirstName,
dbo.[evser].ses as MealChoice,
dbo.[evldg].paid as AmountPaid,
dbo.[names].gp as PreferredAddress,
dbo.[names].mi as MiddleInitial,
dbo.[names].nname as NickName,
dbo.[names].xname as Suffix,
dbo.[names].hphone as HomePhone,
dbo.[names].email as EmailAddress,
dbo.[names].addr1 as HomeAddress1,
dbo.[names].addr2 as HomeAddress2,
dbo.[names].city as City,
dbo.[names].st as State,
dbo.[names].zip as ZipCode,
dbo.[firms].fname1 as FirmName1,
dbo.[firms].fname2 as FirmName2,
dbo.[firms].faddr1 as FirmAddress1,
dbo.[firms].faddr2 as FirmAddress2,
dbo.[firms].fcity as FirmCity,
dbo.[firms].fst as FirmState,
dbo.[firms].fzip as FirmZip,
dbo.[firms].fphone as FirmPhone,
dbo.[names].udflist1
FROM dbo.[firms]
INNER JOIN dbo.[names]
ON dbo.[firms].firm = dbo.[names].firm
INNER JOIN dbo.evldg
ON dbo.[names].id = dbo.[evldg].id
INNER JOIN dbo.evser
ON dbo.[evldg].id = dbo.[evser].id
WHERE dbo.[evldg].code1 = @Code1 AND dbo.[evser].code1 = @Code1 AND dbo.[names].xwebflag <> 'Y'
ORDER BY dbo.[names].lname, dbo.[names].fname
GO


We run a report for our members of people that have signed up for a class. What I need to do is add another table evreg but I don't want to duplicate names which are already being pulled from evser in the above code. How would I add this?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-03-27 : 16:23:42
It's best to show us a data example since we aren't familiar with your schema. What do you mean by duplicate names?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

jpcraw
Starting Member

3 Posts

Posted - 2008-03-27 : 16:27:24
When someone signs up for a meeting and selects a session for that meeting, their info is stored in the table evser, but if they do not choose a session they info is only stored here: evreg. So they could be in both tables or only in evreg. What is happening when the report is pulled it's not pulling names from evreg only evser. I want to add evreg to the SP, but not duplicate their names if they are in both tables. Does that make sense?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-03-27 : 16:30:59
Use an OUTER JOIN to evreg.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

jpcraw
Starting Member

3 Posts

Posted - 2008-03-27 : 16:36:08
So like this?

OUTER JOIN dbo.evser
ON dbo.[evreg].id = dbo.[evser].id

Do I need to add anything to the where statement?

Thanks so much for your help
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-03-27 : 16:46:01
First, it should be to evreg since evser is already in your joins. Specify either LEFT JOIN or LEFT OUTER JOIN. See SQL Server Books Online for join details and syntax.

Second, try the updated code and let us know what issues you see.

Third, it's hard to know without showing us a data example as mentioned in my first reply. Show us sample rows of your current code and then what it should look like after the change has been made.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -