Solved

stored procedure determines which query to run based on value sent from vb.net application

Posted on 2008-10-07
2
157 Views
Last Modified: 2012-05-05
I have a stored procedure that I execute from my VB.NET application.  I want to have 2 query options in the sproc so it will return different values depending on the variable I send to the sproc.

In my code I have option 1 query and option 2 query.

How can I run only one query based on a value in a variable (I want either JobNumber or EstimateNumber.... Not Both) ?
SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

-- =============================================

-- Author:		Jason Hammond

-- Create date: 10/7/2008

-- Description:	Fills datagrid on salesmainpage when customer selected

-- =============================================

Alter PROCEDURE APP_FillDataGridonSalesMain
 

@ccustno varchar(50) = NULL,

@jobstatus int = NULL,

@jobvoid int = NULL
 

AS

BEGIN

	
 

	SET NOCOUNT ON;
 

select  
 

-- Option 1 query
 

EstimateNumber [Est Number]

,JobDescriptions [Description]

,convert(varchar(12),CreateDate,101) Created

,convert(varchar(12),DueDate,101) Due

,Priority Priority

, case 

when jobstatus = 1 then 'Open'

when jobstatus = 2 then 'Complete'

when jobstatus = 3 then 'Billed'

when jobstatus = 5 then 'Estimate'

end  as [Job Status]
 

from sales_jobentry

where Ccustno = isnull(@Ccustno,ccustno) 

and jobstatus = isnull(@jobstatus,jobstatus)

and jobvoid = isnull(@jobvoid,0)
 
 

-- Option 2 Query
 
 
 
 

select  
 

JobNumber  [Job Number]

,JobDescriptions [Description]

,convert(varchar(12),CreateDate,101) Created

,convert(varchar(12),DueDate,101) Due

,Priority Priority

, case 

when jobstatus = 1 then 'Open'

when jobstatus = 2 then 'Complete'

when jobstatus = 3 then 'Billed'

when jobstatus = 5 then 'Estimate'

end  as [Job Status]
 

from sales_jobentry

where Ccustno = isnull(@Ccustno,ccustno) 

and jobstatus = isnull(@jobstatus,jobstatus)

and jobvoid = isnull(@jobvoid,0)
 
 
 
 
 

END

GO

Open in new window

0
Comment
Question by:logoncom
2 Comments
 
LVL 60

Accepted Solution

by:
chapmandew earned 500 total points
ID: 22661299
If @Value = 1
BEGIn
run query 1 here
END
ELSE
BEGIN
run query 2 here.
END
0
 

Author Closing Comment

by:logoncom
ID: 31503919
Great, Thanks
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Group by correlation 4 55
How to SUM hours for the same record 1 34
Insert from Stored Procedure where some field/s > 0 7 43
Unable to save view in SSMS 21 59
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
In this article I will describe the Copy Database Wizard 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.
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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

18 Experts available now in Live!

Get 1:1 Help Now