Stored Procedure With Unknown Numer Of Paramters, How?
Mar 29, 2006
I have one table with categories
tblCategories
cat_id | cat_name
-----------------
1 | cat 1
2 | cat 2
3 | cat 3
4 | cat 4
5 | cat 5
6 | cat 6
and one table with projects which relates to tblCategories
tblProjects
proj_id | proj_name | cat_id
----------------------------
1 | proj 1 | 2
2 | proj 2 | 2
3 | proj 3 | 3
4 | proj 4 | 2
How would you create stored procedure for searching some string in
filed proj_name but within multiple categories
for example
CREATE PROCEDURE [spSearch]
(
@SEARCH_STRING nvarchar(200),
@CAT_ID int
)
AS
BEGIN
SELECT proj_id
FROM tblProjects
WHERE (proj_name LIKE '%' + @SEARCH_STRING + '%') AND (cat_id =
@CAT_ID)
END
But that one works only with one categorie and i need to search for one
or more categories at once, does anyone have a solution? Is there
something like ellipsis (...) in C++ for MSSQL?
View 7 Replies
ADVERTISEMENT
Sep 13, 2007
Hi all,
I am trying to debug stored procedure using visual studio. I right click on connection and checked 'Allow SQL/CLR debugging' .. the store procedure is not local and is on sql server.
Whenever I tried to right click stored procedure and select step into store procedure> i get following error
"User 'Unknown user' could not execute stored procedure 'master.dbo.sp_enable_sql_debug' on SQL server XXXXX. Click Help for more information"
I am not sure what needs to be done on sql server side
We tried to search for sp_enable_sql_debug but I could not find this stored procedure under master.
Some web page I came accross says that "I must have an administratorial rights to debug" but I am not sure what does that mean?
Please advise..
Thank You
View 3 Replies
View Related
Sep 27, 2007
Hi,
I have table with four fields ID, Date1, Date2,Date3,Date4. Dates are in numeric farmat like 20070927. How can i get largest date (from date1 to date4) on each row. Please suggest query.
Thanks
View 19 Replies
View Related
May 1, 2007
Hi,
I'm using MS Report Designer 2005 and have created a report that uses a cube, with a dimension set up to convert null values to unknown (nullProcessing = UnknownMember).
When I create a parameter using the checkbox in the graphical design mode's filter pane, Report Designer automatically sets the constrained flag, eg:
STRTOMEMBER(@DimOrganisationBUSADDRSTATE, CONSTRAINED).
When running the report and selecting the 'Unkown' value from the parameter list, the error 'the restrictions imposed by the CONSTRAINED flag in the STRTOSET function were violated' occurrs.
How can I prevent the constrained flag from being used, or am I doing something wrong with converting null values to 'Unknown'?
Thanks
View 10 Replies
View Related
Jul 20, 2005
This is what I want to do:1. Delete all tables in database with table names that ends with anumber.2. Leave all other tables in tact.3. Table names are unknown.4. Numbers attached to table names are unknown.5. Unknown number of tables in database.For example:(Tables in database)AccountAccount1Account2BinderBinder1Binder2Binder3.......I want to delete all the tables in the database with the exceptionof Account and Binder.I know that there are no wildcards in the "Drop Table tablename"syntax. Does anyone have any suggestions on how to write this sqlstatement?Note: I am executing this statement in MS Access with the"DoCmd.RunSQL sql_statement" command.Thanks for any help!
View 2 Replies
View Related
Jan 24, 2007
If a procedure is known but all parameters are not known, can I handle this using CommandBehavior.RetrieveParameters.
If yes, do I need to incur an extra round trip to server.
View 1 Replies
View Related
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
Nov 4, 2007
I am in a SQL Class and I am starting to learn about SQL Parameters in conjunction with using them from a C# program. I have a couple of questions.
1. When I include an Output parameter in the list or paramters that I send, SQL always is returning a message indicating that the parameter was missing, when I know in fact that I am passing the paramter (@RtnMsg)
2. When I remove any reference to "@RtnMsg", which it can not find, and execute the stored procedure it always returns a -1 and never inserts the record.
Here is my code for the stored procedure....
ALTER procedure [dbo].[Insert_Biblio]
@ISBN as char(11),
@CALL_NO as char(20),
@DEWEY_NO as char(20),
@AUTHOR as char(5),
@TITLE as char(100),
@AUTHOR_BORN as int,
@AUTHOR_DIED as int,
@PUBLISHER as char(30),
@YEAR_PUBLISHED as int,
@BOOK_INFO as char(49),
@BOOK_HEIGHT as int,
@BIBLIO_INFO as char(100),
@COST as money,
@TOPIC_1 as char(30),
@TOPIC_2 as char(30),
@RtnMsg as varchar(50) output
as
declare @Book_ID as char(5);
begin
Set @RtnMsg = 'Insert Successful'
return 0
select @Book_ID = max(book_ID) + 1
from collection
insert into biblio
(BOOK_ID,ISBN, CALL_NO, DEWEY_NO, AUTHOR, TITLE,
AUTHOR_BORN, AUTHOR_DIED, PUBLISHER, YEAR_PUBLISHED,
BOOK_INFO, BOOK_HEIGHT, BIBLIO_INFO, COST,
TOPIC_1, TOPIC_2)
values (@BOOK_ID,@ISBN, @CALL_NO, @DEWEY_NO,
@AUTHOR, @TITLE, @AUTHOR_BORN,
@AUTHOR_DIED, @PUBLISHER, @YEAR_PUBLISHED,
@BOOK_INFO, @BOOK_HEIGHT, @BIBLIO_INFO,
@COST, @TOPIC_1, @TOPIC_2)
return 0
end
Here is the C# program code (this version is the one where SQL tells me @RtnMsg is missint.
SqlParameter[] parms = new SqlParameter[16];
parms[0] = new SqlParameter("@ISBN", SqlDbType.Char, 11);
parms[0].Value = (txtISBN.Text.Length == 0 ? (object)DBNull.Value : txtISBN.Text);
parms[1] = new SqlParameter("@CALL_NO", SqlDbType.Char, 20);
parms[1].Value = (txtCallNbr.Text.Length == 0 ? (object)DBNull.Value : txtCallNbr.Text);
parms[2] = new SqlParameter("@DEWEY_NO", SqlDbType.Char, 20);
parms[2].Value = (txtDewerNbr.Text.Length == 0 ? (object)DBNull.Value : txtDewerNbr.Text);
parms[3] = new SqlParameter("@AUTHOR", SqlDbType.Char, 5);
parms[3].Value = (txtAuthor.Text.Length == 0 ? (object)DBNull.Value : txtAuthor.Text);
parms[4] = new SqlParameter("@TITLE", SqlDbType.Char, 100);
parms[4].Value = (txtTitle.Text.Length == 0 ? (object)DBNull.Value : txtTitle.Text);
parms[5] = new SqlParameter("@AUTHOR_BORN", SqlDbType.Int);
parms[5].Value = (txtAuthorDOB.Text.Length == 0 ? (object) DBNull.Value : Convert.ToInt32(txtAuthorDOB.Text));
parms = new SqlParameter("@AUTHOR_DIED", SqlDbType.Int);
parms.Value = (txtAuthorDOD.Text.Length == 0 ? (object) DBNull.Value : Convert.ToInt32(txtAuthorDOD.Text) );
parms[7] = new SqlParameter("@PUBLISHER", SqlDbType.Char, 30);
parms[7].Value = (txtPublisher.Text.Length == 0 ? (object)DBNull.Value : txtPublisher.Text);
parms = new SqlParameter("@YEAR_PUBLISHED", SqlDbType.Int);
parms.Value = (txtYearPublished.Text.Length == 0 ? (object) DBNull.Value : Convert.ToInt32(txtYearPublished.Text) );
parms[9] = new SqlParameter("@BOOK_INFO", SqlDbType.Char, 49);
parms[9].Value = (txtBookInfo.Text.Length == 0 ? (object)DBNull.Value : txtBookInfo.Text);
parms[10] = new SqlParameter("@BOOK_HEIGHT", SqlDbType.Int);
parms[10].Value = (txtBookHeight.Text.Length == 0 ? (object)DBNull.Value : Convert.ToInt32(txtBookHeight.Text));
parms[11] = new SqlParameter("@BIBLIO_INFO", SqlDbType.Char, 100);
parms[11].Value = (txtBiblioInfo.Text.Length == 0 ? (object)DBNull.Value : txtBiblioInfo.Text);
parms[12] = new SqlParameter("@COST", SqlDbType.Money);
parms[12].Value = (txtCost.Text.Length == 0 ? (object)DBNull.Value : Convert.ToDouble(txtCost.Text));
parms[13] = new SqlParameter("@TOPIC_1", SqlDbType.Char, 30);
parms[13].Value = (txtTopic1.Text.Length == 0 ? (object)DBNull.Value : txtTopic1.Text);
parms[14] = new SqlParameter("@TOPIC_2", SqlDbType.Char, 30);
parms[14].Value = (txtTopic2.Text.Length == 0 ? (object)DBNull.Value : txtTopic2.Text);
parms[15] = new SqlParameter("@RtnMsg", SqlDbType.VarChar, 50);
parms[15].Direction = ParameterDirection.Output;
foreach(SqlParameter parm in parms)
{
if (parm.ParameterName != "@ReturnValue")
{ parm.Direction = ParameterDirection.Input; }
}
string conStr = System.Configuration.ConfigurationManager.ConnectionStrings["CIS277ConnectionString"].ConnectionString;
SqlConnection cn = new SqlConnection(conStr);
SqlCommand cmd = new SqlCommand("dbo.Insert_Biblio", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddRange(parms);
cn.Open();
int rtnCode = cmd.ExecuteNonQuery();
View 1 Replies
View Related
Mar 3, 2008
Hi all,
I have 2 sets of sql code in my SQL Server Management Stidio Express (SSMSE):
(1) /////--spTopSixAnalytes.sql--///
USE ssmsExpressDB
GO
CREATE Procedure [dbo].[spTopSixAnalytes]
AS
SET ROWCOUNT 6
SELECT Labtests.Result AS TopSixAnalytes, LabTests.Unit, LabTests.AnalyteName
FROM LabTests
ORDER BY LabTests.Result DESC
GO
(2) /////--spTopSixAnalytesEXEC.sql--//////////////
USE ssmsExpressDB
GO
EXEC spTopSixAnalytes
GO
I executed them and got the following results in SSMSE:
TopSixAnalytes Unit AnalyteName
1 222.10 ug/Kg Acetone
2 220.30 ug/Kg Acetone
3 211.90 ug/Kg Acetone
4 140.30 ug/L Acetone
5 120.70 ug/L Acetone
6 90.70 ug/L Acetone
/////////////////////////////////////////////////////////////////////////////////////////////
Now, I try to use this Stored Procedure in my ADO.NET-VB 2005 Express programming:
//////////////////--spTopSixAnalytes.vb--///////////
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sqlConnection As SqlConnection = New SqlConnection("Data Source = .SQLEXPRESS; Integrated Security = SSPI; Initial Catalog = ssmsExpressDB;")
Dim sqlDataAdapter As SqlDataAdapter = New SqlDataAdaptor("[spTopSixAnalytes]", sqlConnection)
sqlDataAdapter.SelectCommand.Command.Type = CommandType.StoredProcedure
'Pass the name of the DataSet through the overloaded contructor
'of the DataSet class.
Dim dataSet As DataSet ("ssmsExpressDB")
sqlConnection.Open()
sqlDataAdapter.Fill(DataSet)
sqlConnection.Close()
End Sub
End Class
///////////////////////////////////////////////////////////////////////////////////////////
I executed the above code and I got the following 4 errors:
Error #1: Type 'SqlConnection' is not defined (in Form1.vb)
Error #2: Type 'SqlDataAdapter' is not defined (in Form1.vb)
Error #3: Array bounds cannot appear in type specifiers (in Form1.vb)
Error #4: 'DataSet' is not a type and cannot be used as an expression (in Form1)
Please help and advise.
Thanks in advance,
Scott Chang
More Information for you to know:
I have the "ssmsExpressDB" database in the Database Expolorer of VB 2005 Express. But I do not know how to get the SqlConnection and the SqlDataAdapter into the Form1. I do not know how to get the Fill Method implemented properly.
I try to learn "Working with SELECT Statement in a Stored Procedure" for printing the 6 rows that are selected - they are not parameterized.
View 11 Replies
View Related
Jan 12, 2000
Does anyone have a way of finding all parameters with default values, for any stored procedure in a database?
aTdHvAaNnKcSe!
View 1 Replies
View Related
Jul 20, 2005
From previous postings I have read it seems that I cannot create afunction that accepts a variable list of parameters. Seems that SQLServer does not support this.A few questions:Is this true?What is a workaround?Then how does the function COALESCE do it?Cut and pasted from online books:SyntaxCOALESCE ( expression [ ,...n ] )ArgumentsexpressionIs an expression of any type.nIs a placeholder indicating that multiple expressions can bespecified. All expressions must be of the same type or must beimplicitly convertible to the same type.
View 3 Replies
View Related
Nov 15, 2007
What is the proper syntax for the SET transact-sql for mult-value parameters? Is this even possible?
Code Block
declare @Name char(55);
set @Name = 'name1';
select *
from table1
where name in (@Name)
How do I write the SET line so that it will behave like this:
where name in ('name1','name2','name3')
I'm sure this is an easy one, I'm currently looking it up, but thought someone might be able to answer this for me quick.
Thanks much!
View 5 Replies
View Related
Feb 28, 2008
i have a query in SQL Server 2005 that uses a parameter like so:ALTER Procedure [dbo].[p_FullTextEquipmentSearch]
@search as nvarchar(50),
as
SELECT * FROM EquipmentView
where contains(*, @search);
what i want to so is add more parameters to the query so that the user can choose either 1 or many for the search can anyone help me on this
View 2 Replies
View Related
Nov 27, 2007
Hi there,
I've got a RS2000 report from Analysis services 2000. This report is working fine but after the upgrade to SQL2K5, i'm having issues with changes to parameters.
Basically i'm passing DateQuarter, CustomersLevel as parameters to the following mdx script. I've tried to change mdx script in RS2005 but no luck yet. I don't much about the parameter level changes in sql2k5. So can anyone suggest what is wrong in the script.
Code Block
RS2000
="with " &
"member [Measures].[Ex Price] as 'coalesceempty([Measures].[Ex Price After Trade Discount - Detail],0.00)' " &
"set [Rolling Quarters] as '" + Parameters!DateQuarter.value +".lag(4):" + Parameters!DateQuarter.value + "'" &
"SELECT " &
"{[Measures].[Ex Price]} ON COLUMNS , " &
"filter({CrossJoin([Items by Class].[Item Class Description].members, [Rolling Quarters])}, [Measures].[Ex Price] > 0) on Rows " &
"FROM Sales " &
"WHERE (" & Parameters!CustomersLevel.Value & ")"
RS2005
with
member [Measures].[Ex Price] as 'coalesceempty([Measures].[Ex Price After Trade Discount - Detail],0.00)'
set [Rolling Quarters] as '@DateQuarter' +'.lag(4):' + '@DateQuarter'
SELECT
{[Measures].[Ex Price]} ON COLUMNS ,
filter({CrossJoin([Items by Class].[Item Class Description].members, [Rolling Quarters])}, [Measures].[Ex Price] > 0) on Rows
FROM Sales
WHERE STRTOSET(@CustomersLevel)
Thanks in advance,
Vivek
View 4 Replies
View Related
Nov 14, 2006
Hello,
I just installed the new SQL 2005 sp2 CTP on my stand alone report server. Now whenever a parmeter is not multi-value I get
One or more data sources is missing credentials
when clicking off the parameter. If I set the parameter to multi-value it works fine but confuses the users.
Does anyone know how to debug this or if a fix is available ? Yes it was working before I installed the service pack.
View 3 Replies
View Related
Apr 28, 2008
We are using MS Reporting Services to generate Xmls for corporate billing statements. Our DBAs found that MS ReportingServices are querying Oracle Catalogue before executing stored procedures in RDLs to get Oracle parameter information. Is there a way to eliminate the trip to database before executing the stored procedures?
Hongmei
View 1 Replies
View Related
Nov 14, 2014
I am new to work on Sql server,
I have One Stored procedure Sp_Process1, it's returns no of columns dynamically.
Now the Question is i wanted to get the "Sp_Process1" procedure return data into Temporary table in another procedure or some thing.
View 1 Replies
View Related
Jan 29, 2015
I have some code that I need to run every quarter. I have many that are similar to this one so I wanted to input two parameters rather than searching and replacing the values. I have another stored procedure that's executed from this one that I will also parameter-ize. The problem I'm having is in embedding a parameter in the name of the called procedure (exec statement at the end of the code). I tried it as I'm showing and it errored. I tried googling but I couldn't find anything related to this. Maybe I just don't have the right keywords. what is the syntax?
CREATE PROCEDURE [dbo].[runDMQ3_2014LDLComplete]
@QQ_YYYY char(7),
@YYYYQQ char(8)
AS
begin
SET NOCOUNT ON;
select [provider group],provider, NPI, [01-Total Patients with DM], [02-Total DM Patients with LDL],
[Code] ....
View 9 Replies
View Related
Sep 19, 2006
I have a requirement to execute an Oracle procedure from within an SQL Server procedure and vice versa.
How do I do that? Articles, code samples, etc???
View 1 Replies
View Related
Sep 20, 2007
Using gridview to display the data and sql server 2000 I have
a column in the database say departtime of datetime datatype that
cntains the date and time resp(09/19/2007 9:00 PM). I am separating the
date and time parts to display in two different textboxes say
txt1(09/19/2007) contaons date and txt2(9:00 PM) contains time by using
the convert in sqldatasource. Now i need to update the column in the
database and i am using Updatecommand with parameters in aspx lke
updatecommand = "Update table set departtime = @departtime" . How can
i update my column as datetime by getting the data from 2 texboxes as
now i have 2 textboxes displaying data for single column means if user
edit the data in txt1 as(10/19/2007) then on click of update i need to
populate the column daparttime as (10/19/2007 9:00 PM).Please let me know if you have any questions.
View 1 Replies
View Related
Nov 5, 2007
Hi
Im writing a program that stores data to SQL server 2005.
Program writen on VC++ 2003.
Code is very simple and it works ok if server runs and parameters are ok.
try
{
HRESULT hr = m_Connection.CreateInstance(__uuidof(ADODB::Connection));
String ConnectionStr;
ConnectionStr.Format(_T("Provider=sqloledb;Data Source=%s;Initial Catalog=MyDB;User Id=%s;Password=%s;"),m_Server.c_str(),m_Username.c_str(),m_Password.c_str());
_bstr_t bstrConnection(ConnectionStr.c_str());
m_Connection->CursorLocation = ADODB::adUseClient;
hr = m_Connection->Open(bstrConnection, L"", L"", ADODB::adConnectUnspecified);
}
catch(_com_error &e)
{
_bstr_t Description = e.Description();
}
But!
if i give wrong paramterer for Data Source , it may happen if user configures it and misprints it, or if server goes offline for some reason, program just hangs on m_Connection->Open and never gives exception as it should.
Any ideas what wrong?
Thanks.
View 4 Replies
View Related
Dec 28, 2005
I have a sub that passes values from my form to my stored procedure. The stored procedure passes back an @@IDENTITY but I'm not sure how to grab that in my asp page and then pass that to my next called procedure from my aspx page. Here's where I'm stuck: Public Sub InsertOrder() Conn.Open() cmd = New SqlCommand("Add_NewOrder", Conn) cmd.CommandType = CommandType.StoredProcedure ' pass customer info to stored proc cmd.Parameters.Add("@FirstName", txtFName.Text) cmd.Parameters.Add("@LastName", txtLName.Text) cmd.Parameters.Add("@AddressLine1", txtStreet.Text) cmd.Parameters.Add("@CityID", dropdown_city.SelectedValue) cmd.Parameters.Add("@Zip", intZip.Text) cmd.Parameters.Add("@EmailPrefix", txtEmailPre.Text) cmd.Parameters.Add("@EmailSuffix", txtEmailSuf.Text) cmd.Parameters.Add("@PhoneAreaCode", txtPhoneArea.Text) cmd.Parameters.Add("@PhonePrefix", txtPhonePre.Text) cmd.Parameters.Add("@PhoneSuffix", txtPhoneSuf.Text) ' pass order info to stored proc cmd.Parameters.Add("@NumberOfPeopleID", dropdown_people.SelectedValue) cmd.Parameters.Add("@BeanOptionID", dropdown_beans.SelectedValue) cmd.Parameters.Add("@TortillaOptionID", dropdown_tortilla.SelectedValue) 'Session.Add("FirstName", txtFName.Text) cmd.ExecuteNonQuery() cmd = New SqlCommand("Add_EntreeItems", Conn) cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.Add("@CateringOrderID", get identity from previous stored proc) <------------------------- Dim li As ListItem Dim p As SqlParameter = cmd.Parameters.Add("@EntreeID", Data.SqlDbType.VarChar) For Each li In chbxl_entrees.Items If li.Selected Then p.Value = li.Value cmd.ExecuteNonQuery() End If Next Conn.Close()I want to somehow grab the @CateringOrderID that was created as an end product of my first called stored procedure (Add_NewOrder) and pass that to my second stored procedure (Add_EntreeItems)
View 9 Replies
View Related
Sep 26, 2014
I have a stored procedure and in that I will be calling a stored procedure. Now, based on the parameter value I will get stored procedure name to be executed. how to execute dynamic sp in a stored rocedure
at present it is like EXECUTE usp_print_list_full @ID, @TNumber, @ErrMsg OUTPUT
I want to do like EXECUTE @SpName @ID, @TNumber, @ErrMsg OUTPUT
View 3 Replies
View Related
Nov 16, 2007
In SQL 2000, working with Maintenance plan wizard, what would be best settings and values should i choose in "Update Data Optimization information" window,
Thanks,
View 6 Replies
View Related
Mar 5, 2008
SELECT ArticleID, ArticleTitle, ArticleDate, Published, PublishDate, PublishEndDateFROM UserArticlesWHERE (ArticleDate >= PublishDate) AND (ArticleDate <= PublishEndDate)
When I use the above on a GridView I get nothing. Using SQL manager it works great.
I don't know how to pass the value of the ArticleDate field as a default parameter or I think that's what I don't know how to do.
I am trying to create a app that I can set the dates an article will appear on a page and then go away depending on the date.
Thanks for any help!
View 1 Replies
View Related
Mar 28, 2007
I have a stored procedure that calls a msdb stored procedure internally. I granted the login execute rights on the outer sproc but it still vomits when it tries to execute the inner. Says I don't have the privileges, which makes sense.
How can I grant permissions to a login to execute msdb.dbo.sp_update_schedule()? Or is there a way I can impersonate the sysadmin user for the call by using Execute As sysadmin some how?
Thanks in advance
View 9 Replies
View Related
Jan 23, 2008
Has anyone encountered cases in which a proc executed by DTS has the following behavior:
1) underperforms the same proc when executed in DTS as opposed to SQL Server Managemet Studio
2) underperforms an ad-hoc version of the same query (UPDATE) executed in SQL Server Managemet Studio
What could explain this?
Obviously,
All three scenarios are executed against the same database and hit the exact same tables and indices.
Query plans show that one step, a Clustered Index Seek, consumes most of the resources (57%) and for that the estimated rows = 1 and actual rows is 10 of 1000's time higher. (~ 23000).
The DTS execution effectively never finishes even after many hours (10+)
The Stored procedure execution will finish in 6 minutes (executed after the update ad-hoc query)
The Update ad-hoc query will finish in 2 minutes
View 1 Replies
View Related
Mar 31, 2008
I have a stored procedure 'ChangeUser' in which there is a call to another stored procedure 'LogChange'. The transaction is started in 'ChangeUser'. and the last statement in the transaction is 'EXEC LogChange @p1, @p2'. My questions is if it would be correct to check in 'LogChange' the following about this transaction: 'IF @@trancount >0 BEGIN Rollback tran' END Else BEGIN Commit END.
Any help on this would be appreciated.
View 1 Replies
View Related
Oct 10, 2006
Hi,I am getting error when I try to call a stored procedure from another. I would appreciate if someone could give some example.My first Stored Procedure has the following input output parameters:ALTER PROCEDURE dbo.FixedCharges @InvoiceNo int,@InvoiceDate smalldatetime,@TotalOut decimal(8,2) outputAS .... I have tried using the following statement to call it from another stored procedure within the same SQLExpress database. It is giving me error near CALL.CALL FixedCharges (@InvoiceNo,@InvoiceDate,@TotalOut )Many thanks in advanceJames
View 16 Replies
View Related
Nov 15, 2006
I have a store procedure (e.g. sp_FetchOpenItems) in which I would like to call an existing stored procedure (e.g. sp_FetchAnalysts). The stored proc, sp_FetchAnalysts returns a resultset of all analysts in the system.
I would like to call sp_FetchAnalysts from within sp_FetchOpenItems and insert the resultset from sp_FetchAnalysts into a local temporary table. Is this possible?
Thanks,
Kevin
View 3 Replies
View Related
May 18, 2007
This is the Stored Procedure below ->
SET QUOTED_IDENTIFIER ON GOSET ANSI_NULLS ON GO
/****** Object: Stored Procedure dbo.BPI_SearchArchivedBatches Script Date: 5/18/2007 11:28:41 AM ******/if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[BPI_SearchArchivedBatches]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)drop procedure [dbo].[BPI_SearchArchivedBatches]GO
/****** Object: Stored Procedure dbo.BPI_SearchArchivedBatches Script Date: 4/3/2007 4:50:23 PM ******/
/****** Object: Stored Procedure dbo.BPI_SearchArchivedBatches Script Date: 4/2/2007 4:52:19 PM ******/
CREATE PROCEDURE BPI_SearchArchivedBatches( @V_BatchStatus Varchar(30)= NULL, @V_BatchType VARCHAR(50) = NULL, @V_BatchID NUMERIC(9) = NULL, @V_UserID CHAR(8) = NULL, @V_FromDateTime DATETIME = '01/01/1900', @V_ToDateTime DATETIME = '01/01/3000', @SSS varchar(500) = null, @i_WildCardFlag INT)
AS
DECLARE @SQLString NVARCHAR(4000)DECLARE @ParmDefinition NVARCHAR (4000)
IF (@i_WildCardFlag=0)BEGIN
SET @SQLString='SELECT Batch.BatchID, Batch.Created_By, Batch.RequestSuccessfulRecord_Count, Batch.ResponseFailedRecord_Count, Batch.RequestTotalRecord_Count, Batch.Request_Filename, Batch.Response_Filename, Batch.LastUpdated_By, Batch.LastUpdated, Batch.Submitted_By, Batch.Submitted_On, Batch.CheckedOut_By, Batch.Checked_Out_Status, Batch.Batch_Description, Batch.Status_Code, Batch.Created_On, Batch.Source, Batch.Archived_Status, Batch.Archived_By, Batch.Archived_On, Batch.Processing_Mode, Batch.Batch_TemplateID, Batch.WindowID,Batch.WindowDetails, BatchTemplate.Batch_Type, BatchTemplate.Batch_SubType FROM Batch INNER JOIN BatchTemplate ON Batch.Batch_TemplateID = BatchTemplate.Batch_TemplateID WHERE ((@V_BatchID IS NULL) OR (Batch.BatchID = @V_BatchID )) AND ((@V_UserID IS NULL) OR (Batch.Created_By = @V_UserID )) AND ((Batch.Created_On >= @V_FromDateTime ) AND (Batch.Created_On <= @V_ToDateTime )) AND Batch.Archived_Status = 1 '
if (@V_BatchStatus IS not null) begin set @SQLString=@SQLString + ' AND (Batch.Status_Code in ('+@V_BatchStatus+'))' end
if (@V_BatchType IS not null) begin set @SQLString=@SQLString + ' AND (BatchTemplate.Batch_Type in ('+@V_BatchType+'))' end END
ELSEBEGIN SET @SQLString='SELECT Batch.BatchID, Batch.Created_By, Batch.RequestSuccessfulRecord_Count, Batch.ResponseFailedRecord_Count, Batch.RequestTotalRecord_Count, Batch.Request_Filename, Batch.Response_Filename, Batch.LastUpdated_By, Batch.LastUpdated, Batch.Submitted_By, Batch.Submitted_On, Batch.CheckedOut_By, Batch.Checked_Out_Status, Batch.Batch_Description, Batch.Status_Code, Batch.Created_On, Batch.Source, Batch.Archived_Status, Batch.Archived_By, Batch.Archived_On, Batch.Processing_Mode, Batch.Batch_TemplateID, Batch.WindowID,Batch.WindowDetails, BatchTemplate.Batch_Type, BatchTemplate.Batch_SubType FROM Batch INNER JOIN BatchTemplate ON Batch.Batch_TemplateID = BatchTemplate.Batch_TemplateID WHERE ((@V_BatchID IS NULL) OR (isnull (Batch.BatchID, '''') LIKE @SSS )) AND ((@V_UserID IS NULL) OR (isnull (Batch.Created_By , '''') LIKE @V_UserID )) AND ((Batch.Created_On >= @V_FromDateTime ) AND (Batch.Created_On <= @V_ToDateTime )) AND Batch.Archived_Status = 1 '
if (@V_BatchStatus IS not null) begin set @SQLString=@SQLString + ' AND (Batch.Status_Code in ('+@V_BatchStatus+'))' end
if (@V_BatchType IS not null) begin set @SQLString=@SQLString + ' AND (BatchTemplate.Batch_Type in ('+@V_BatchType+'))' end
END
PRINT @SQLString
SET @ParmDefinition = N' @V_BatchStatus Varchar(30), @V_BatchType VARCHAR(50), @V_BatchID NUMERIC(9), @V_UserID CHAR(8), @V_FromDateTime DATETIME , @V_ToDateTime DATETIME, @SSS varchar(500)'
EXECUTE sp_executesql @SQLString, @ParmDefinition, @V_BatchStatus , @V_BatchType , @V_BatchID, @V_UserID , @V_FromDateTime , @V_ToDateTime , @SSS
GO
SET QUOTED_IDENTIFIER OFF GOSET ANSI_NULLS ON GO
The above stored procedure is related to a search screen where in User is able to search from a variety of fields that include userID (corresponding column Batch.Created_By) and batchID (corresponding column Batch.BatchID). The column UserID is a varchar whereas batchID is a numeric.
REQUIREMENT:
The stored procedure should cater to a typical search where any of the fields can be entered. meanwhile it also should be able to do a partial search on BatchID and UserID.
Please help me regarding the same.
Thanks in advance.
Sandeep Kumar
View 2 Replies
View Related
Apr 29, 2008
I have a stored procedure that among other things needs to get a total of hours worked. These hours are totaled by another stored procedure already. I would like to call the totaling stored procedure once for each user which required a loop sort of thing
for each user name in a temporary table (already done)
total = result from execute totaling stored procedure
Can you help with this
Thanks
View 10 Replies
View Related