Problems Calling A Stored Procedures Depending On Parameters

Dec 10, 2007

Hi guys, hoping one of you may be able to help me out. I am using VS 2005, and VB.net for a Windows application.

I have a table in SQL that has a list of Storedprocedures:  Sprocs Table: SPID - PK (int), ID (int), NAME (string), TYPE (string)
The ID is a Foreign key (corresponding to a Company ID), the name is the stored procedure name, and Type (is the type of SP).

On my application I need to a certain SP depending on the company selected and what page you are on. I have a seperate SP that passes in parameters for both Company, and Type and should output the Name value:

ALTER PROCEDURE [dbo].[S_SPROC]
( @ID int, @TYPE CHAR(10), @NAME CHAR(20) OUTPUT )
AS

SELECT @NAME = NAME
FROM SPROCS
WHERE [ID] = @ID
AND [TYPE] = @TYPE

Unfortunately I dont seem to be able to get the output in .Net, or then be able to fill my dataset with the Stored Procedure.
Has anyone done something similar before, or could point me in the right direction to solving this problem.

Thanks
Phil

 

View 8 Replies


ADVERTISEMENT

Calling Stored Procedures From C#

Jul 1, 2007

Hi All...  I'm calling a stored procedure from C#.  I'm sending it input parameters as follows:SqlCommand c = new SqlCommand("AddAuthor", myConnection);c.CommandType = CommandType.StoredProcedure;
c.Parameters.Add(new SqlParameter("@LastName", SqlDbType.VarChar, 100));c.Parameters["@LastName"].Value = "Last";
c.Parameters.Add(new SqlParameter("@FirstName", SqlDbType.VarChar, 100));c.Parameters["@FirstName"].Value = "First";
In my opinion, that works nice - and it's easy.  The reference I'm using says I can also specify "output" parameters - instead of supplying a value, one needs to change a property called direction. 
But my stored procedure doesnt return any output parameters per se, but it does return a value.  That is the last statement in the stored procedure is "RETURN @@IDENTITY" - it returns the identity field after an INSERT...  So how do I get that value back in my C# code?
Thanks for the help in advance.  Happy 4th to all!  : )    -- Curt
 

View 4 Replies View Related

Calling Stored Procedures Via Vb.net

Jan 16, 2008

Hi,
 I was wondering if someone can tell me why my sub for calling stored procedures doesn't work.The string strFinFileId is not null.
I keep getting the following error System.IndexOutOfRangeException: Total
Here's my sub.
 '//get GrandTotal    Protected Sub GetGrandTotal(ByVal finfileid As String)        Dim myConnection As SqlConnection        Dim connString As String        Dim strFinFileId As String        Dim strGrandTotal As Decimal
        strFinFileId = finfileid        connString = ConfigurationManager.ConnectionStrings("PMOConnectionString1").ConnectionString
        myConnection = New SqlConnection(connString)        'you need to provide password for sql server        myConnection.Open()
        Dim sql1 As String
        sql1 = "GetGrandTotal " & Convert.ToInt32(strFinFileId)
        Dim myCommand As SqlCommand
        'Response.Write(sql1)        'Response.End()
        myCommand = New SqlCommand(sql1, myConnection)
        Dim reader As SqlDataReader = myCommand.ExecuteReader()        While reader.Read()            strGrandTotal = reader.Item("Total")            LabelGrandTotal.Text = strGrandTotal            'Response.Write(strFinFileId)            'Response.End()
        End While        reader.Close()        myConnection.Close()    End Sub
 Cheers
Mark :) 
 

View 2 Replies View Related

Help W. Calling Stored Procedures

Apr 16, 2008

I have a stored procedure written to update a table:
The stored procedure  has the following parameters:
@Original_TypeID int,
@Type_Desc varchar(35),
@Contact_Name varchar(20),
@Contact_Ad1 varchar(25),
@Contact_Ad2 varchar(25),
@Contact_City varchar(10),
@Contact_Phone varchar(12),
@Contact_Fax varchar(12),
@Contact_Email varchar(35)
And I want to call this procedure when the "update" button is clicked, my code is:Protected Sub UpdateButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("myConnectionString").ConnectionString)Dim myCommand As SqlCommandDim UpdteParam As New SqlParameter()
myConnection.Open()myCommand = New SqlCommand("[dbo].[sp_Update_Types]", myConnection)
myCommand.CommandType = CommandType.StoredProcedure
????????????????????????myCommand.Parameters.Add(UpdateParam)
 
???????????myCommand.ExecuteNonQuery()
myConnection.Close()
End Sub
 
Can you please help me with the ????? areas? I don't know how to pass the parameters into the procedure, and also the second set of ??? s, I'm not sure if I am executing the command correctly.
Thank you.

View 3 Replies View Related

Stored Procedures Calling DLL's

Jun 21, 2001

I'm relatively new to SQL Server and I was wondering if there is any way to call a DLL from a regular stored procedure? I believe I've read that the extended stored procedure is a DLL and therefore should be able to call another DLL. Can this also be verified? We're looking to speed up some sections of Visual Basic code which does some heavy I/O work. I've also asked this once before but didn't get an absolute answer - can you write the extended stored procedures in Visual Basic or is C/C++ the only language supported right now?

Thanks.

Caroline Kaplonski
ckaplonski@buckconsultants.com

View 2 Replies View Related

Calling Stored Procedures

Jul 20, 2005

Hi AllI was wondering if there is a way to call a stored procedure from insideanother stored procedure. So for example my first procedure will call asecond stored procedure which when executed will return one record and iwant to use this data in the calling stored procedure. Is this possible ?Thanks in advance

View 18 Replies View Related

Calling Stored Procedures From Different DBs

Jul 20, 2005

Is it possible to have a stored procedure in database A while callingit from database B and have it manipulate the tables in database B(whatever the calling database happens to be)?We have a large-scale app that uses many complex stored procedures,and as of now, we're copying the SPs to every new database that iscreated, and it will soon become a nightmare for propagating updatesand fixes. We'd like to keep a master set of the SPs in one DB and"use" them from other DBs so that they only query data and manipulatetables in the calling DB. I hope someone has some suggestions. Thanks.

View 1 Replies View Related

Calling Stored Procedures In SQL Statement

Aug 25, 2007

How can we call Stored Procedure inside any SQL Statement
For Example.
If we have procedure name sprocCurrentPriority
select * from tablename where colmunname = exec sprocCurrentPriority

View 7 Replies View Related

Calling Stored Procedures On Different Servers

Oct 4, 2004

I'm using reporting services to build a report and I plan on using a stored procedure to gather my data for the report. My question is:

I know it's possible to call a stored procedure from a stored procedure, both within the same dB and in different dB's, but is it possible to call a SP that's on a different server? My gut says "definitely not. at least not easily." But I wanted to see if anyone had any thoughts on this before I pursue a different course of action.

View 3 Replies View Related

Calling Stored Procedures In MS Access

Nov 3, 2000

can anyone tell me how to call SQL stored procedures in MS Access97...
appreciate any help

View 4 Replies View Related

Calling Stored Procedures From A Web Page

Jan 15, 2001

I am currently developing web pages based on data pulled from SQL Server with ASP. I've mastered the art of SELECTing, INSERTing, etc, but want to know if it is possible to run STored Procedures from a page by clicking on a button on a particualr web page.

View 1 Replies View Related

Calling Sql Server Stored Procedures From C#

Apr 3, 2008



I have a simple stored procedure:


create procedure sp_testres

@mult1 int,

@mult2 int,

@result int output

as

select @result = (10*@mult1) + @mult2

go



When I call it


declare @result int

exec sp_testres 5, 6, @result output

print @result

(Result is correctly shown as 56).

I then in C# wrote the following:



m_cmd.CommandText = "sp_testres";

SqlParameter param2 = new SqlParameter("@mult2", SqlDbType.Int);

param2.Value = 6;

SqlParameter param1 = new SqlParameter("@mult1", SqlDbType.Int);

param1.Value = 5;

SqlParameter param3 = new SqlParameter("@result", SqlDbType.Int);

param3.Direction = ParameterDirection.Output;

m_cmd.CommandType = CommandType.StoredProcedure;

m_cmd.Parameters.Add(param1);

m_cmd.Parameters.Add(param2);

m_cmd.Parameters.Add(param3);

m_cmd.ExecuteNonQuery();


This works and param3.Value holds the result value.
I also notice that I can supply the parameters in any order, and things work fine.

What I want to know is: can I call the stored procedure with parameters, where I haven't supplied the parameter name, and just rely on the parameter order matching instead?

View 5 Replies View Related

Calling Stored Procedures Using Plain ADO In C#

Sep 7, 2006

Hello All,

We are trying to figure out how to make a stored procedure call and pass some inputs using C# and plain ADO. We are able to call an empty stored procedure but cannot pass parameters into a stored procedure.

Does anyone have sample code in C# whereby we can open a connection and pass inputs into a stored procedure? The following is a sample code we are using:


ADODB.Parameter param = new ADODB.Parameter();

param=cmd.CreateParameter("@StoreID", ADODB.DataTypeEnum.adInteger, ADODB.ParameterDirectionEnum.adParamInput,sizeof(int) , 9);

cmd.Parameters.Append(param);

          ADODB.Recordset rsInv = cmd.Execute(out objAffected, ref objAffected,-1 );

In the above example, we create a parameter of type integer and try to add it to the ADO Command object. It is supposed to return a recordset. It returns a recordset with record count -1.

 

Sincerely,

Dwight Kulkarni

View 3 Replies View Related

Calling Stored Procedures From Another Stored Procedure

May 8, 2008

I am writing a set of store procedures (around 30), most of them require the same basic logic to get an ID, I was thinking to add this logic into an stored procedure.

The question is: Would calling an stored procedure from within an stored procedure affect performance? I mean, would it need to create a separate db connection? am I better off copying and pasting the logic into all the store procedures (in terms of performance)?

Thanks in advance

John

View 5 Replies View Related

Calling Stored Procedures Inside Cursors

Aug 13, 2001

I have created a cursor using the following type of syntax:

DECLARE MyCursor CURSOR FOR
SELECT ID FROM tblEmployees
OPEN MyCursor
BEGIN
FETCH NEXT FROM MyCursor
END
CLOSE MyCursor

Instead of the SELECT statement (SELECT ID FROM tblEmployees), I actually have a very complex select statement. I have created a stored procedure to handle this select. However, I cannot find a way to call a stored procedure in place of the SELECT statement in the cursor. Is this possible? Thanks.

View 2 Replies View Related

Calling Stored Procedures In A Select Statement

Feb 26, 2004

I am trying to call a stored procedure inside a SQL SELECT statement. Has anybody had to do this in the past? I have a SELECT statement in a Microsoft Access database and I need that SELECT statement to call the stored procedure in the SQL server. Any help would be appreciated

View 4 Replies View Related

Calling Stored Procedures From Back End C# Codings In ASP .net Designing

Nov 21, 2007

I writte a stored procedure for username , password ....
How can i call that stored procedure to verify the username & password 
then if both match in the database redirected to next page..? in asp with c#.net back end programming
 

View 2 Replies View Related

Esql/C Calling Stored Procedure With Output Parameters

Dec 6, 2004

I'm trying to write an esqlc program that will run a stored procedure that returns several output parameters. I haven't been able to find any documentation to date that explains how to run the "EXEC SQL EXECUTE procname" command and specify the output parameters.

My stored procedure "aek_proc1" takes one input parameter (p1 - an 8-character string) and 3 output parameters (p2 - an integer; p3 - an 8-character string, and p4 a 40-character string).

My esqlc program contains the following code….

EXEC SQL BEGIN DECLARE SECTION;
char p1[9];
int p2;
char p3[9];
char p4[41];
WXEC SQL END DECLARE SECTION;

sprintf(&p1[0], "GL");
p2 = 0;
sprintf(&p3[0], "");
sprintf(&p4[0], "");

EXEC SQL EXECUTE aek_proc1 :p1,
:p2 OUTPUT,
:p3 OUTPUT,
:p4 OUTPUT;

I am getting errors at runtime about constants being passed for OUTPUT parameters.

I can run the same stored procedure in Query Analyser and it works beautifully (see below)

declare @p1 char(8)
declare @p2 integer
declare @p3 char(8)
declare @p4 char(40)

set @p1 = 'GL'

execute aek_proc1 @p1, @p2 output, @p3 output, @p4 output

select @p1 p1, @p2 p2, @p3 p3, @p4 p4

Any idea what I'm doing wrong or how it should be coded?

I'd really appreciate any advice you can offer!!

I've spend hours browsing this newsgroup and found lots of examples of how to do this in VB and from Query Analyser but I can't find any examples for ESQL/C that work.

So, please help!!!

Thanks,

AllanK :rolleyes:

View 3 Replies View Related

Calling A Stored Procedure On A Data Source (with Parameters)

Nov 29, 2007

This seems to be much more difficult than it was in DTS (or perhaps I just need to adjust to the new way of doing things).

Eventually I found that I needed to use "SQL command from variable" and using two other variables as input parameters. The expresion for the command is

"usp_ValveStatusForDay '" + @[User:ate] + "','" + @[User::Report] + "'"

which typically evaluates as

usp_ValveStatusForDay '18 Oct 07','Report_Name'

This previews correctly and the resulting columns are available for mapping to a destination. So far so good.

By the way, is this the best way to call a stored procedure with parameters?

I have pasted the stored procedure at the end of this posting because I have come accross a puzzling problem. The query as shown below works correctlly but if I un-comment the delete statement, the preview still works and the columns are still avilable for mapping but I get the following errors when the package is executed.


Error: 0xC02092B4 at Data Flow Task, OLE DB Source [1]: A rowset based on the SQL command was not returned by the OLE DB provider.

Error: 0xC004701A at Data Flow Task, DTS.Pipeline: component "OLE DB Source" (1) failed the pre-execute phase and returned error code 0xC02092B4.

I realise that I could execute the delete query in a separate SSIS package step but I am curious as to why there is a problem with the way I tried to do it.

At one stage the stored procedure used a temp table and later I also experimented with a table variable. In both cases I got similar errors at execution time. In the case of the temp table there was another problem in that, while the preview worked, there were no columns available for mapping. Using a table variable seemed to overcome this problem but I still got the run time error. eventually I found a way to avoid using either a temp table or a table variable and the package then worked correctly, copying the data into the desitnation table.

It seems to me that if there is any complexity at all to the stored procedure, these errors seem to occur. Can anyone enlighten me as to what the "rules of engagement" are in this regard? Is one solution to use a wrapper stored procedure that simply calls the more complex one?



ALTER procedure [dbo].[usp_ValveStatusForDay]

(

@dateTime DateTime,

@reportName VarChar(100)

)

AS

BEGIN

DECLARE @day VarChar(10)

DECLARE @month VarChar(10)

DECLARE @year VarChar(10)

DECLARE @start VarChar(25)

DECLARE @end VarChar(25)

SET @day = Convert(Varchar(10),DatePart(day, @dateTime))

SET @month = Convert(VarChar(10), DatePart(month, @dateTime))

SET @year = Convert(VarChar(10), DatePart(year, @dateTime))

IF @month = '1' SET @month = 'Jan'

IF @month = '2' SET @month = 'Feb'

IF @month = '3' SET @month = 'Mar'

IF @month = '4' SET @month = 'Apr'

IF @month = '5' SET @month = 'May'

IF @month = '6' SET @month = 'Jun'

IF @month = '7' SET @month = 'Jul'

IF @month = '8' SET @month = 'Aug'

IF @month = '9' SET @month = 'Sep'

IF @month = '10' SET @month = 'Oct'

IF @month = '11' SET @month = 'Nov'

IF @month = '12' SET @month = 'Dec'

SET @start = @day + ' ' + @month + ' ' + @year + ' 00:00:00'

SET @end = @day + ' ' + @month + ' ' + @year + ' 23:59:59'

--delete from ValveStatus where SampleDateTime between dbo.ToBigInt(@start) and dbo.ToBigInt(@end)

exec dbo.usp_ValveStats_ReportName @reportName, @start, @end, '1h'

END

View 8 Replies View Related

Using EXECUTE Statements Calling An Extended Stored Procedures From Function..

Apr 29, 2004

Hi, all
I'm using Sql server 2000
I want to make select statement dynamically and return table using function.
in sp, I've done this but, in function I don't know how to do so.
(I have to create as function since our existing API..)

Following is my tials...
1.
alter Function fnTest
( @fromTime datetime, @toTime datetime)
RETURNS Table
AS

RETURN Exec spTest @from, @to
GO

Yes, it give syntax error..

2. So, I found the following


From Sql Server Books Online, Remark section of CREATE FUNCTION page of Transact-SQL Reference , it says following..

"The following statements are allowed in the body of a multi-statement function. Statements not in this list are not allowed in the body of a function: "
.....
* EXECUTE statements calling an extended stored procedures.

So, I tried.

alter Function fnTest
( @fromTime datetime, @toTime datetime)
RETURNS Table
AS

RETURN Exec master..xp_msver
GO

It doesn't work... syntax err...

Here I have quick question.. How to execute statements calling an extended stored procedures. any examples?


Now, I'm stuck.. how can I create dynamic select statement using function?

I want to know if it's possible or not..

View 13 Replies View Related

Calling A Stored Procedure Inside Another Stored Procedure (or Nested Stored Procedures)

Nov 1, 2007

Hi all - I'm trying to optimized my stored procedures to be a bit easier to maintain, and am sure this is possible, not am very unclear on the syntax to doing this correctly.  For example, I have a simple stored procedure that takes a string as a parameter, and returns its resolved index that corresponds to a record in my database. ie
exec dbo.DeriveStatusID 'Created'
returns an int value as 1
(performed by "SELECT statusID FROM statusList WHERE statusName= 'Created') 
but I also have a second stored procedure that needs to make reference to this procedure first, in order to resolve an id - ie:
exec dbo.AddProduct_Insert 'widget1'
which currently performs:SET @statusID = (SELECT statusID FROM statusList WHERE statusName='Created')INSERT INTO Products (productname, statusID) VALUES (''widget1', @statusID)
I want to simply the insert to perform (in one sproc):
SET @statusID = EXEC deriveStatusID ('Created')INSERT INTO Products (productname, statusID) VALUES (''widget1', @statusID)
This works fine if I call this stored procedure in code first, then pass it to the second stored procedure, but NOT if it is reference in the second stored procedure directly (I end up with an empty value for @statusID in this example).
My actual "Insert" stored procedures are far more complicated, but I am working towards lightening the business logic in my application ( it shouldn't have to pre-vet the data prior to executing a valid insert). 
Hopefully this makes some sense - it doesn't seem right to me that this is impossible, and am fairly sure I'm just missing some simple syntax - can anyone assist?
 

View 1 Replies View Related

Stored Procedures And Parameters

Nov 22, 2006

How many parameters can I use for a Stored Procedure.
 

View 4 Replies View Related

Using Stored Procedures With Parameters

Jun 18, 2004

Hi all,

Just a quick question regarding the use of stored procedures with parameters.

How do I call a stored procedure with a different number of parameters?

For example if:

new SqlParameter("@SectionID", "3"),
new SqlParameter("@Sessionid", Session["ID"])

SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, sqlParams);

were to change to the following on a different page:

new SqlParameter("@SectionID", "3"),
new SqlParameter("@Sessionid", Session["ID"]),
new SqlParameter("@ExtraVariable", ExtraVariable)

SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, sqlParams);


How would I handle the different number of parameters in the Stored Procedure?

cheers,

Pete

View 1 Replies View Related

Stored Procedures And Parameters

Jun 23, 1998

I want to create a stored procedure with SQL Server 6.5 that CAN take 3 parameters, all of which are optional. The declaration for the stored procedure is :
CREATE PROCEDURE BackOrdersII @CustCode varchar(10), @FromDate datetime, @ToDate datetime AS
SELECT * FROM ISO_Details
WHERE DATEDIFF(dd, fldEst_Del_Date, getdate()) > 0 AND CONVERT(char(12),fldActual_Del_Date,3)=`01/01/00` AND CONVERT(char(12),fldEst_Del_Date,3)<>`01/01/00` AND fldDeleted<>1
ORDER BY DATEDIFF(dd, fldEst_Del_Date, getdate()) DESC

How do I formulate the procedure to allow me to select from the table, keeping the current WHERE clause but adding extra items to allow the results to be further filtered depending upon which of the parameters are given to the procedure. Any one, two, or all three parameters could be given.

Sorry if this seems like a simple question but I am only just getting into using stored procedures.

Thanks Rupert

View 1 Replies View Related

Stored Procedures And Parameters

Aug 24, 2004

Have looked everywhere and cannot find the answer! So perhaps someone here can answer.

I have an Access 2000 front-end to a SQL Server 2000 database.

I know how to create Stored Procedures that receive parameters; and also how to open a Stored Procedure in the query results window using the DoCmd object. For example,

Application.DoCmd.OpenStoredProcedure "MyProc", acViewNormal, acReadOnly

Does anyone know of a way to pass parameters to Stored Procedures & open the result using the DoCmd object? Without getting a parm input dialog?

Alternatively, does anyone know of a way to open a Stored Procedure in the query results view without using the DoCmd object?

Will appreciate any guidance you can provide! Thanks!

CarlR

View 3 Replies View Related

Stored Procedures With Parameters (in .adp)

Jul 20, 2005

I use a stored procedure that is calling several other stored procedurewhich update or append values in several tables. All of them are storedprocedures with input parameters by which they filter rows to be updated orinserted into other tables.Filtration is based on certain actual values on forms (form with severalsubforms).My question is following: How to pass parameters to those stored proceduresthat are triggered by a button?Those stored procedures are not recordset of forms, so I can't pass it usingInput Parameters property of forms (or I can?).Thanks.Zlatko

View 1 Replies View Related

Which Is A Better Stored Procedures Verse Parameters

Mar 28, 2007

 
 
My colleague and I (both are newbie’s to .NET) are divided on whether to use stored procedures or parameters.
 
His viewpoint is, using stored procedures you are spreading the load i.e. SQL server and web server etc. This is not a good solution because it is not a portable when it has to be relocated.
 
Is he right?
 
I thought to avoid SQL injection it is best to use stored procedures but I do see his reasoning as well.
 
Yazzy is Very confused!!
 Thanks in advance for any of your thoughts

View 2 Replies View Related

Table Parameters In Stored Procedures

Dec 9, 2007

How can I pass a name of a table to a stored procedure.
I want to pass the name as a parameter. The table already exists in the db.
After that, I will do
"SELECT .....
FROM @tableparameter"
What is the right way to do that?

View 3 Replies View Related

Passing Parameters To Stored Procedures

Feb 17, 2005

Hello,

I seached around for an answer to this question but didn't have much luck. Hopefully someone can help.

I am passing two parameters from a web page to a stored procedure. The first paramater @Field is the name of the field in the database I want to search, the second @Value is the value to seach for. The @Value works fine but the SP does not seem to recongnize the field parameter. I'm not sure if what I am attemping is not supported or wheather I just need to format the @Field in a different manner. The code and stored procedure is below.

Thanks for your help, Gary

Here is the web code:


Dim conMSS As New SqlConnection(ConfigurationSettings.AppSettings("dsnMSS"))
Dim cmdItems As New SqlCommand("DS-SPRS.dbo.s_ItemLookUp", conMSS)

cmdItems.CommandType = CommandType.StoredProcedure
cmdItems.Parameters.Add(New SqlParameter("@Field", SqlDbType.VarChar, 50))
cmdItems.Parameters.Add(New SqlParameter("@Value", SqlDbType.VarChar, 50))

cmdItems.Parameters("@Value").Value = txtValue.Text & "%"
cmdItems.Parameters("@Field").Value = lstField.SelectedValue

conMSS.Open()
dgdItems.DataSource = cmdItems.ExecuteReader
dgdItems.DataBind()
conMSS.Close()


Here is the stored procedure:



CREATE PROCEDURE s_ItemLookUp

@Field AS VARCHAR(50),
@Value AS VARCHAR(50)

AS


SELECT DIV_NO, DIV_NM, LN_NO, LN_DS, ITM_NO, PRD_DS, ITM_MFG_NO, VND_HFC_NM
FROM PRODUCT
WHERE @Field LIKE @Value
ORDER BY DIV_NO, LN_NO, ITM_NO
GO

View 4 Replies View Related

Putting @Parameters In Stored Procedures

Nov 18, 2005

I am creating a stored Procedure and I am getting an error which relates to DATENAME.
SELECT COUNT(*) AS calls, DATENAME(@varDate, CALLSTARTTIME) AS 'Total Calls'
FROM CALL_LOG_MASTER
WHERE (COMMERCIALS='1') AND (CALLSTARTTIME >= @StartDate) AND (CALLENDTIME <=@EndDatesql doesn't like: DATENAME( @varDate, CallStartTime)sql works fine if I change @varDate into 'yy', 'mm', 'dd', or 'wk'Since I do not want to make 5 unique Stored Proc just because of @varDate.....Is there any way to work around this problem?

View 8 Replies View Related

Stored Procedures And Optional Parameters

Mar 5, 1999

I need to create a SP that will accept a varying number of input parameters. A form that the user completes has a several controls that serve to narrow the number of records returned. The more parameters given, the fewer rows returned. In the past I have accomplished this by dynamically building an SQL statement. I dosen't appear possible to pass an SQL statement in a variable to a SP. Any help or pointers would be appreciated.

View 1 Replies View Related

Set Date Parameters Within Stored Procedures?

Feb 15, 2012

I need to set date parameters within Stored Procedures using a sql 2008 R2, with an access 2007 front end. The procedure needs to allow me to set parameters for a start date and an end date.

View 1 Replies View Related

Identifying Specified Parameters In Stored Procedures

Jul 20, 2005

I am using SQL Server 2000. I have a table with, say, 20 columns. Ihave one procedure which updates all 20 columns at once, accepting aparameter for each column. However, I want to be able to pass anycombination of parameters and only update those columns if passed. SoI created the sp as something likecreate update_t1(@col1 int = null,@col2 int = null,@col3 int = null,....@col20 int = null)asupdate t1set col1 = @col1,col2 = @col2,col3 = @col3,.....col20 = @col20This way I can explicitly specify columns or not as I choose. Forexample I could call "exec update_t1 @col1 = 23, @col4 = 49" to updateonly the first and fourth column. Of course this will obviouslyupdate the remaining columns to null. Is there any way to identifywithin the procedure which parameters were actually specified? Ican't simply do a null check because the user could be updating thevalue to be null. Is there any way for the procedure to know theexact command that invoked it?For example, if I called "exec update_t1 @col1 = 23, @col4 = 49" Iwould want to know only col1 and col4 were specified. If I called"exec update_t1 @col1 = 23, @col4 = 49, @col17 = null" I would want toknow that col1, col4 and col17 were specified, even though col17 wasset to the default of null.

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved