stored-procedures

OUTPUT clause for Stored Procedure vs Table-Valued Function

I'm studying for the MCTS 70-433 "Database Design" cert, and in the text that I'm studying, one of the self-tests has this question. You have a stored procedure named Get_NewProducts. You wish to insert the results of this stored procedure into the Production.Product table and output the INSERTED.* values using the OUTPUT ...

Mysql restore database through stored procedure

Hi All, I want to restore mysql database through stored procedure? Is it possible? Or can I copy dbfile and rename that folder? Please let me know if anyone needs more information to answer this question. Thanks in advance. Regards, Manasi ...

How to pass a nullable string to an SP from C#

I have a string property that may or may not be null. I am passing it to the SP using this call: db.AddInParameter(InsertMessageDetailCommand, "MyParam", System.Data.DbType.String, this.myParam); the field is defined in the SP like this: @MyParam nvarchar(50) How can I change the SP to allow for null values, and if param value is...

How to return table from T-SQL Stored Procedure

SQL Newbie here, and I'm having a hell of a time finding what should be a simple code example to answer what I think is a simple question. I need to write a stored procedure that does three things in order: 1) Select rows from one table 2) Update rows in another table, using values from the results table in #1 3) Return the results tabl...

What is the best way to determine if a timestamp falls within seasonal business hours?

I want a SQL query to check if a given timestamp falls within the open hours of a business. These open hours change depending on the time of year (seasonal hours) and the business is closed for certain holidays. I have a list of these dates, although they are subject to change. What I want is a good structure for storing this informat...

Is LINQ-to-SQL + SQLite.NET + Stored Procedures + VISUAL STUDIO 2008 possible?

Hi. So I want to retrieve data using stored procedures. Preferably via Linq2SQL. So I can do something like this (example): var productHistory = dbname.StoredProcedureMethod(value); foreach(var product in productHistory) { //stuff } This is something I'd like to be able to do in Visual Studio 2008 in .Net 3.5. It is possible wit...

Is it good practice to use one single stored procedure that accepts a variable number of parameters

I am working on a web project where I have to retrieve (let's say) employee records. In some cases I have to retrieve a single record by providing an EmployeeID. In other cases, I have to retrieve multiple employee records by providing a SectorID. This logic could be expanded to cover additional scenarios: get all employee records, get e...

Stored procedures in entity framework

I am trying to use a stored procedure in the entity framework that returns nothing. The stored procedure is purely for logging. I added a function (right click -> add -> function import) which works ONLY when the return value is set to one of the entities. When I change the return type to be Int32, Bool or nothing, or any other value ...

Where should database queries live?

Should queries live inside the classes that need the data? Should queries live in stored procedures in the database so that they are reusable? In the first situation, changing your queries won't affect other people (either other code or people generating reports, etc). In the second, the queries are reusable by many and only exist in o...

Swapping sql query for stored procedure and confused about return value

Hi, This is a bit of code in one of the pages I am reviewing and trying to update. What I am trying to do is swap the inline query for stored procedures. This is the bit of code: numOfDelRec = 1 Do While (numOfDelRec > 0) cm.CommandText = "DELETE Folder WHERE FolderID IN (SELECT ch.FolderID FROM Folder ch LEFT JOIN Folder p...

Deleting from 2 tables at the same time?

I'm using asp.net and sql server. i have 2 tables: Categories and Products. in the products table i have categoryId as FK. what i want to do is: when i delete category from the category table, i want that all the products from that category will be deleted in the products table. how can this be done ( i prefer with store procedure but it...

T/F: Using IF statements in a procedure produces multiple plans

In responses to this question, KM said if you are on or above SQL Server 2005, you can use IFs to have multiple queries in the same procedure and each will have an query plan saved for it (equiv to a procedure for each on older versions), see the article in my answer or this link to proper section: sommarskog.se/dyn-search-2005.html#...

Qualifications for answering: Are the days of stored procedures numbered

Looking at all the answers to the question: "Are the days of stored procedures numbered". It appears as if some people are jumping in with strong opions based on what I perceive to be a narrow range of software development experiences. I would like to re-submit the question, but first I need help putting together a list of qualificatio...

SQL Server StoredProc vs UDF inline table

I have written a complex query that will return me a list of IDs. Now I want to re-use this query so that I join the results with another query. For that I plan to put this into a Stored Proc or an UDF and then use it to insert into a temp table. Something like below 1) Put the query in a Stored Proc and insert it into temp table INSE...

MySQL Prepared Statements vs Stored Procedures Performance

Hi there, I have an old MySQL 4.1 database with a table that has a few millions rows and an old Java application that connects to this database and returns several thousand rows from this this table on a frequent basis via a simple SQL query (i.e. SELECT * FROM people WHERE first_name = 'Bob'. I think the Java application uses client si...

Entity Framework Error: "The container 'XXXX' specified for the FunctionImport could not be found in the current workspace."

I am executing this EntityConnection entityConnection = (EntityConnection)context.Connection; EntityCommand command = entityConnection.CreateCommand(); command.CommandText = "Genesis.AL_Insert"; command.CommandType = CommandType.StoredProcedure; //Parametro de NombrePlantilla EntityPa...

SQL : in clause in storedprocedure:how to pass values

I want to write an SQL Server 2005 stored procedure which will select and return the user records from the user table for some userids which are passed to the stored procedure as parameter. How to do this ? I can pass the user ids as a string separated by comma. So that i can use the select * from users where userid in (userids) ...

MySQL Syntax Error

When executing: BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN ROLLBACK; SELECT 1; END; DECLARE EXIT HANDLER FOR SQLWARNING BEGIN ROLLBACK; SELECT 1; END; -- delete all users in the main profile table that are in the MaineU18 by email address DELETE FROM ap_form_1 WHERE element_5 ...

Working with a QueryString and placing value in Stored Procedure?

I am working with ASP.NET and SQL Server 2005. I know how to create a stored proceudre but i do not know what to place in a stored procedure when i need to make use of a QueryString. My SQL Statement in CODE = "SELECT * FROM TableName WHERE ID = '" + Request.QueryString("ID") + "'" Now what must i place in my stored procedure to get...

Can I update the result (sys_refcursor) of an Oracle stored procedure (in Java)?

Given the following function: create or replace FUNCTION "GETADDRESSES" RETURN sys_refcursor IS address_cursor sys_refcursor; BEGIN OPEN address_cursor FOR SELECT * FROM Address; RETURN address_cursor; END; I would like to be able to make changes to this result set in Java and post the changes back to the data...