stored-procedures

Should prepared statements be deallocated when used inside stored procedures?

Hi! When using prepared statements inside stored procedures, should they be deallocated at the end of the procedure or not, or does it not matter, and why? Some code to explain: CREATE PROCEDURE getCompanyByName (IN name VARCHAR(100)) NOT DETERMINISTIC BEGIN PREPARE gcbnStatement FROM 'SELECT * FROM Companies WHERE name=? LIMIT 1'; ...

how can i call the delete store procedure in linq query

how can i call the delete store procedure in linq query ...

SQL Filter Query

I have a table with a number of fields in it. I am trying to create search filter in asp.net so the user can search by one or a combination of fields. So basically I want to create a single stored procedure that takes in 4 params and it will append the param to the WHERE clause if its not null... TableExample has 4 columns, Col1 Col2 Co...

Get resultset from oracle stored procedure

Hi all I'm working on converting a stored procedure from SQL server to Oracle. This stored procedure provides a direct resultset. I mean that if you call the stored procedure in eg Management Studio you directly obtain the resultset. By converting to Oracle I walk against the problem that I in Oracle will not display the resultset ...

When should I use stored procedures?

When should I be using stored procedures instead of just writing the logic directly in my application? I'd like to reap the benefits of stored procedures, but I'd also like to not have my application logic spread out over the database and the application. Are there any rules of thumb that you can think of in reference to this? ...

SQL Sub Query NO execute if null

I was wondering if there was a way to not execute my subquery if my @ID1 is NULL? CREATE PROCEDURE [dbo].[TestTable_Search] @Col1 int, @Col2 uniqueidentifier, @Col3 datetime, @Col4 datetime, @ID1 varchar(10) AS SET TRANSACTION ISOLATION LEVEL READ COMMITTED SELECT * FROM [dbo].[TestTable] WHERE [Col1] = CO...

How To Forward Data To An External System If There Were Changes During An INSERT or UPDATE? Use a Trigger? Use Extended Sproc or CLR Integration?

Here's the basics of the system we have in place today. We have a SQL 2005/2008 table defined as: CREATE TABLE [dbo].[Profiles] ( [Firm] [char] (4) NULL , [Account] [char] (10) NOT NULL , [UndSym] [char] (24) NOT NULL , [Updated] [timestamp] NOT NULL , [Data] [image] NOT NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] ...

Does stored procedure help eliminates SQL injection / What are the benefits of stored procedured over normal SQL statement in apps?

Hi. I'm pretty new to SQL world. Here are my questions: What are the benefits of stored procedured over normal SQL statement in applications? Does stored procedure help eliminates SQL injection? In Microsoft SQL Server it is called stored procedure. How about in Oracle, MySQL, DB2, etc.? Thanks for your explanation. ...

SQL Server IF NOT EXISTS Usage?

Ok, so my schema is this: Table: Timesheet_Hours Columns: Timesheet_Id (PK, int) Staff_Id (int) BookedHours (int) Posted_Flag (boolean) This is an extremely simplified version of the table, but it will serve for the purposes of this explaination. Assume that a person can only ever have one timesheet record. What I'm trying to do i...

Need help trying to RANK with a GROUP BY.

Hi folks, I'm having trouble trying to rank each of our students, by the homegroup they are in. Example fake data. HomeGroup 1. Team RED 2. Team BLUE 3. Team Skeet 4. Team GREEN Students 1. John, Score - 34, Team RED 2. Jill, Score - 87.3, Team RED 3. Fred, Score - 41, Team GREEN 4. Jane, Score 93, Team BLUE ... etc. My output is ...

Stored procedure inside a insert statement

I am trying to generate random data for my sql server database. Ive created a stored procedure that takes length of string to be generated but the problem is that it wont allow me to call it inside the insert statement. insert into table1 (varchar_data,int_data) value ((sp_GenerateRandomString 4),CAST(RAND() * 10 AS INT) % 6 + 1 ) al...

SQL Server: Way to syntax check all stored procedures?

i want to ensure that all stored procedures are still syntatically valid. (This can happen if someone renames/deletes a table/column). Right now my solution to check the syntax of all stored procedures is to go into Enterprise Manager, select the first stored procedure in the list, and use the procedure: Enter Alt+C Escape Escape Down...

How should I document an existing system

Hi there, I've just started at a new job with sole responsibility for a large(ish) financial application. It's got about 800 stored procedures, 120 SQL server tables and 18 .net projects with approx 1200 code files. And no documentation other than line comments in the code. As I mend bugs and make ad hoc to the data I want to document w...

Cross DB stored procedures performance in SQL Server 2008

Let's have: $DB an SQL Server database $DBSP1 an SQL Server database containing stored procedures referencing $DB $DBSP2 is exactly like $DBSP1 $SP is a stored procedure Running $SP on $DBSP1 from C# code takes around 1.5s. Running $SP on $DBSP2 from C# code takes around 0.5s. The C# code is very simple and use SqlClient with defau...

Stored Procedure To Table Variable Issue

Okay, what I'm trying to do is take the results from a stored procedure and put them into a temp table... Looks like this: DECLARE @Table TABLE( [ID] int, [CostA] real, [CostB] real, [CostC] real ) INSERT INTO @Table EXECUTE [dbo].[CostProcedure] @RootId = 123 @Rate = 20 --THEN: SELECT * FROM @Table -- Gives Me...

Function vs. Stored Procedure in SQL Server

Hi, I've been learning Functions and Stored Procedure for quite a while but I don't know why and when exactly I should use functions or stored procedure instead of one another. They look same to me maybe because I am kinda newbie about that. Can some one tell me why ? Thanks in advance. ...

Trying to access the results/result-set of a SQL server EXEC statement

Say I've got stored proc 1, that returns some data. how can I execute that stored proc and set some parameters within another stored proc based on the results of that stored proc. For example: Table: UserInfo (UserID [int], Name [varchar], DateOfBirth [datetime] ) Stored Proc 1: CREATE Procedure StoredProc1 @Name [varchar] AS ...

Best Practice - Handling multiple fields, user roles, and one stored procedure

I have multiple fields both asp:DropDownList's and asp:TextBox's. I also have a number of user roles that change the Visible property of certain controls so the user cannot edit them. All of this data is saved with a stored procedure call on PostBack. The problem is when I send in the parameters and the control was not on the page obviou...

syntax error in mysql

I am trying to create a stored procedure in MYSQL. Below is my code which is giving syntax error. Can anyone please help me. CREATE PROCEDURE productpricing ( OUT pl DECIMAL(8,2), OUT ph DECIMAL(8,2), OUT pa DECIMAL(8,2) ) BEGIN SELECT Min(prod_price) INTO pl FROM products; SELECT Max(prod_price...

Prevent nullable parameter in stored procedure with LINQ

Hi, I want to define stored procedure parameters which do not allow null arguments. That @MailItemId int OUTPUT will be not nullable because when I import the stored procedure into the LINQ to SQL designer it says @MailIetmid is ref int? mailItemId. Thanks. ...