Solved

Combine data bases on parameters

Posted on 2009-05-18
2
211 Views
Last Modified: 2012-05-07
I have this sp below...if one of the fields is not null, all data is returned based on that parameter. If 2 parameters are not null, then only data fitting those non null parameters should eb returned and if 3 parameters, etc...as above with 2.  What I'm getting is data for only one parameter even when I input 2.  

If then statement?

Thx

ALTER PROCEDURE [dbo].[usp_getPOC1]

@UserID int = NULL,
@CenterID int = 1,
@ProjectID int = 1

AS

SELECT c.Center_Desc, p.Project, u.UserID, r.Last_Name, r.First_Name, r.Office_Phone, u.User_Email from dbo.tbl_User u
Join dbo.tbl_Registration r on u.UserID = r.UserID, dbo.LU_Center_Site c, dbo.LU_Project p
Where
@UserID is not null and @UserID = u.UserID and u.POC = '1' or
@CenterID is not NULL and @CenterID = c.CenterID or
@ProjectID is not null and @ProjectID = p.ProjectID
ORDER BY r.Last_Name
0
Comment
Question by:Glen_D
2 Comments
 
LVL 32

Accepted Solution

by:
Daniel Wilson earned 500 total points
ID: 24413150
try this:



ALTER PROCEDURE [dbo].[usp_getPOC1]
 

@UserID int = NULL,

@CenterID int = 1,

@ProjectID int = 1
 

AS
 

SELECT c.Center_Desc, p.Project, u.UserID, r.Last_Name, r.First_Name, r.Office_Phone, u.User_Email from dbo.tbl_User u

Join dbo.tbl_Registration r on u.UserID = r.UserID, dbo.LU_Center_Site c, dbo.LU_Project p

Where u.POC = '1' AND --this always requires u.POC to = '1' -- which I think is what you mean.

(@UserID is null OR @UserID = u.UserID) and 

( @CenterID is NULL OR @CenterID = c.CenterID) AND

(@ProjectID is null OR @ProjectID = p.ProjectID)

ORDER BY r.Last_Name

Open in new window

0
 

Author Closing Comment

by:Glen_D
ID: 31582614
Perfect...thx Much  Glen
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now