Solved

Stored Procedure with parameters in ASP.Net

Posted on 2014-04-27
1
412 Views
Last Modified: 2014-04-27
I have a stored procedure in SQL Server I am using to search records and return them for display in an asp.net page (c# code behind). I have 3 parameters I need to use. Owner, Year and Type. By default the page opens to all owners for the current year of both types. Using drop down lists, users can select which owner, what year and which type to return. There are 12 owners, with data from each year for 2009-2014. There are two types to select from. I'm trying to create the stored procedure to select 1 owner OR all owners for a particular year, with either type 1 or type 2. I think I need an if statement or case statement in the stored procedure, but I don't know where to look to find examples. Am I approaching this right, and is there a good example to work with?
0
Comment
Question by:dodgerfan
1 Comment
 
LVL 8

Accepted Solution

by:
Ganapathi earned 500 total points
ID: 40026495
CREATE TABLE TMP(OWNER VARCHAR(10),YEAR_VAL DATETIME, OWNER_TYPE INT)
INSERT INTO TMP SELECT 'OWNR1',GETDATE(),8
INSERT INTO TMP SELECT 'OWNR2',GETDATE(),6
INSERT INTO TMP SELECT 'OWNR3',GETDATE(),4
INSERT INTO TMP SELECT 'OWNR4',GETDATE(),3

DECLARE @TYPE_PARAM INT /* Consider this as the Paramater */
, @OWNER_PARAM CHAR(5)
SELECT @TYPE_PARAM = 2
SELECT @OWNER_PARAM = 'OWNR3'
SELECT
	*
FROM
	TMP
WHERE
   (2 = CASE
   		   WHEN @TYPE_PARAM = 2
		      THEN 2
		   ELSE 1
		END)
OR (@TYPE_PARAM = 1 AND OWNER = @OWNER_PARAM)

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

856 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