stored-procedures

Select records with a substring from another table

Hi, I have this two tables: data id |email _ 1 |[email protected] 2 |[email protected] 3 |zzzgimail.com errors _ error |correct @gmial.com|@gmail.com gimail.com|@gmail.com How can I select from data all the records with an email error? Thanks. ...

SQL Procedure to get the count of child and child's childrens in SQL server 2005

Hi All, I have 4 tables Customers, Orders, Order details and Comments in my db. Customer can have many orders/Comments. Orders can have multiple OrderItems(OrderDetails). What I need is the SQL statement to return the following:- Customerid, CustomerName, TotalOrders, Total OrderItems and NoOfRecentComments. TotalOrders would be the t...

How to execute query based on passed operators <,= by param using Stored Procedures?

I have a stored procedure(SP) where one of it's param passes the operator. The operator can be: <=, >=, = How can I use this in the query? How the operators are passed is not built yet, it can be string represented <= or by using a custom code 1, 2 or 3. What do you think? ...

Passing an array from .Net application to Oracle stored procedure

I need to pass an array from C#.net application to oracle stored procedure. Can anyone please let me know how to go about it? Also, which OracleType type do I use in C# when passing input parameter to stored procedure? FYI, am using System.Data.OracleClient in my C# app. Thanks. ...

how use replace in exec statement in sql server 2008

Hi, I have a stored proc, say, "call_Me" with few parameters: Declare @Greet varchar(100) = 'Hi ||User||' Exec Call_Me 1,'something', @Greet --parameters: bit, string, string during the call, I want to be able to replace the ||User|| bit with something else. normally, in a select statement, I would do this: select 1, 'somethin...

Timeout when I call a stored procedure in SQL Server 2008

From C# with EF, I call a long stored procedure with ExecuteStoreCommand 30 sec after the procedure starts, I have a timeout exception. How can I configure timeout ? On the server or in my C# client ? Thanks ...

What is the fastest code to call multiple stored procedures?

Solution 1 : foreach (var item in itemList) { myContext.ExecuteStoreCommand("EXEC MyProc {0};", item); // Insertion } or Solution 2 : StringBuilder sb = new StringBuilder(); foreach (var item in itemList) { sb.AppendLine(String.Format("EXEC MyProc {0};", item)); // Insertion } myContext.ExecuteStoreCommand(sb.ToString()); ...

iReport with Oracle Stored Procedure

Hi I just installed iReport(Product Version: iReport Professional 3.7.1.1) and try to create exiting crystal report file using iReport to see it makes my life easier. First bump that I faced was Oracle stored procedure. I found below post and tried to apply it. 1) Set the Query language in the Report Query to plsql 2) Use the...

PDO MySQL call retruns unbuffered queries error

I have researched online but most examples or instructions don't seem to apply to what I am trying to accomplish. In short my code should accomplish the following: A stored procedure is called from my php script which returns a dataset I want to loop through and produce rows in a table (for online display purposes). One of the fields ...

Using OUTPUT Parameters within Dynamic SQL within Stored Procedures- Possible?

I have a SP that I have created to check for validations and return an OUTPUT Parameter of 0 (No Error) or 1 (Error). However, I have to run this SP within Dynamic SQL since it will be ran through a loop of different data. Can I pull the OUTPUT from the SP through the EXEC sp_executesql @SQL? I can not post the actual code, but I can g...

Use of StoredProcs in an application

hi. we're in the process of designing an enterprise application & our technical architects suggest that "lets have no sql queries in the code. even if its a simple select call to the database a stored procedure should be written for it in the database & the code should call it." my issue with this is that it seems like a dumb idea to ha...

Inserting new record by stored proc

I want to insert/update record with a specific stored-procedure which performs some business-logic on new record values. I can do this by trigger to ignore new record from directly to be inserted and pass new record values to my stored-procedure to perform appropriate action for passed values? ...

Suggest Generalization code for Calling Stored Procedure in Spring

public class TestProcedure extends StoredProcedure { TestProcedure(BasicDataSource dataSource, String procName) { this.setDataSource(dataSource); this.setSql(procName); this.declareParameter(new SqlParameter("@test", Types.INTEGER)); } public List<Detail> executeProcedure(Integer studentId) { Map inParams = new HashMap(...

declaring temp table in both branches of a sql server stored proc conditional

I want to have a construct in a stored procedure that defines a temporary table one way in one branch of an if-else and another way in the other branch, but this won't compile b/c it says the table is already created. I am imagining something like the following: if begin IF OBJECT_ID(N'tempdb..#tbl') IS NOT NULL DROP TABLE #tbl cr...

sql query takes much long time compared to next run

Hi, I'm running a procedure which takes around 1 minute for the first time execution but for the next time it reduces to around 9-10 seconds. And after some time again it takes around 1 minute. My procedure is working with single table which is having 6 non clustered and 1 clustered indexes and unique id column is uniqueidentifier data...

Bulk insert using stored procedure

I have a query which is working fine: BULK INSERT ZIPCodes FROM 'e:\5-digit Commercial.csv' WITH ( FIRSTROW = 2 , FIELDTERMINATOR = ',', ROWTERMINATOR = '\n' ) but now I want to create a stored procedure for it. I have written below code to make its stored procedure: create proc dbo.InsertZipCode @filepath varcha...

SQL Server 2005: stored procedure to move rows from one table to another

Hello, I have 2 tables of identical schemea. I need to move rows older than 90 days (based on a dataTime column present in the table) from table A to table B. Here is the pseudo code for what I want to do SET @Criteria = getdate()-90 Select * from table A Where column X<@Criteria Into table B --now clean up the records we just moved ...

Stored procedures and Triggers in PostgreSQL

I never used these two features in PostgreSQL. Which language is used to write stored procedures and triggers in PGSQL? Is it the same that Oracle or SQL Server follows or it is C? ...

In a stored procedure, it it better to simply query data or to construct a query and then execute it? why?

I have worked on SQL stored procedures and I have noticed that many people use two different approaches - First, to use select queries i.e. something like Select * from TableA where colA = 10 order by colA Second, is to do the same by constructing a query i.e. like Declare @sqlstring varchar(100) Declare @sqlwhereclause varchar(1...

Stored Procedure Returning Duplicate Invalid Row

SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER Procedure [dbo].[spGetQualityReport] ( @providerKey INT ) AS -- declare @providerKey INT -- set @providerKey = 1; --Get Database providerId first DECLARE @realProvId INT; SET @realProvId = (SELECT TOP(1) providerId from providerKeyTranslation where keyVa...