Solved

Combine data bases on parameters

Posted on 2009-05-18
2
214 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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

929 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

9 Experts available now in Live!

Get 1:1 Help Now