stored-procedures

SQL 2000 - Returning from a Stored Procedure

Hello, I'm writing a stored procedure. This procedure has a case where if it is met, I want to stop executing the procedure and return -1. How do I do this? Currently, I'm trying the following: IF @result <> 1 BEGIN SELECT -1 END However, SELECT is not a typical "return". As you can imagine I spend most of my time ...

SQL Server - How to switch between 2 possible SELECT statements

I would like to use a parameter in my mssql stored procedures to switch between a small and a detailed result (for maintainability, performance and network load reasons). If parameter is set to 1 i get all columns, else only the one or two most important. In a very limited way it works like this: ALTER PROCEDURE [dbo].[GetAllUsers] @d...

SQL IF ELSE with output params stored proc help

Hi All, I have a stored proc (SS2008) that takes a couple int ids and needs to look up if they exist in a table before adding a record. I have an int output param I would like to return and set its value based on what occrured. I have this so far, but it always returns 1. Can someone point me in the right direction? BEGIN TRY IF EXIS...

Dynamic SQL Rows & Columns...cells require subsequent query. Best approach?

I have the following tables below City --------- CityID StateID Name Description Reports --------- ReportID HeaderID FooterID Description I’m trying to generate a grid for use in a .Net control (Gridview, Listview…separate issue about which will be the ‘best’ one to use for my purposes) which will assign the reports as the columns an...

Retrieve input and output parameters for SQL stored procs and functions?

For a given SQL stored proc or function, I'm trying to obtain its input and output parameters, where applicable, in a Winforms app I'm creating to browse objects and display their parameters and other attributes. So far I've discovered the SQL system function object_definition, which takes a given sysobjects.id and returns the text of t...

PL/SQL profiler missing data

We are using pl/sql profiler to collect metrics. We noticed that on one of the environment the plsql_profiler_runs table is populated with the total execution time but the finer details that gets collected in the table plsql_profiler_data is missing. Any idea why this would be happening? We do use dbms_profiler.flush_data() before stopp...

Copy a Table's data from a Stored Procedure

I am learning how to use SQL and Stored Procedures. I know the syntax is incorrect: Copy data from one table into another table on another Database with a Stored Procedure. The problem is I don't know what table or what database to copy to. I want it to use parameters and not specify the columns specifically. I have 2 Databases (Master...

Calling Stored Procedure from VB.net timeout error

When calling a stored procedure from vb.net is there a default SQL timeout time if no timeout is specified in the connection string? I am unsure if there is a CommandTimeout specified in the connection string but am going through all the possibilites. Example if no results after 30 seconds (or more) throw: `System.Data.SqlClient.SqlExc...

joins- how to pass the parameter in stored procedure to execute a join query

i have used joins to get datas from two tables under comman name. as SELECT userValidity.UserName, userValidity.ValidFrom,userValidity.ValidUpTo,userValidity.TotalPoints, persons.SenderID FROM userValidity INNER JOIN persons ON userValidity.Username=tbl_persons.Username but i need to execute this query with oly the username which i p...

Are there stored procedure writing guidelines?

There are a lot of information about how to write an stored procedure from a practical view, in a very database server language dependent way, but since I and the team that I work everyday already know that, I was looking for a more theoretical discussion about how to do this, in some way language or database server independent. I want ...

Is there anything else I can do to optimize this MySQL query?

I have two tables, Table A with 700,000 entries and Table B with 600,000 entries. The structure is as follows: Table A: +-----------+---------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+---------------------+------+-----+---------+-------...

Doctrine: Keep 'Timestampable' behavior when using stored procedures?

I have complex logic which is not possible (too slow) to run through PHP with Doctrine, so I need to create a stored procedure for this. The logic also includes inserting/updating records in a table using the Timestampable behavior. How do I preserve this behavior in the stored procedure? ...

How to pass and Return a Array to stored procedure?

I would like to know how to pass an array to a stored procedure which in turn will return an array from c# .net? ...

Stored procedure for selecting multiple records

I need to select records say 2000 from a table with a matching timestamp from c# .net code. Eg: SELECT * FROM ITEMDATA_TABLE WHERE ITEMNAME='Item1' and TimeStamp='2010-04-26 17:15:05.667' The above query has to execute for 2000 items more for the same timestamp. for this we can use SELECT * FROM ITEMDATA_TABLE WHERE ITEMNAME in...

Export view data programmatically in Access/SQL Server

We have an Access application front-end connected to a SQL Server 2000 database. We would like to be able to programmatically export the results of some views to whatever format we can (ideally Excel, but CSV / tab delimited is fine). Up until now we've just hit F11, opened up the view, and hit File->Save As, but we're starting to get re...

Stored procs breaking overnight

We are running MS SQL 2005 and we have been experiencing a very peculiar problem the past few days. I have two procs, one that creates an hourly report of data. And another that calls it, puts its results in a temp table, and does some aggregations, and returns a summary. They work fine...until the next morning. The next morning, s...

TSQL - create a stored proc inside a transaction statement

I have a sql script that is set to roll to production. I've wrapped the various projects into separate transactions. In each of the transactions we created stored procedures. I'm getting error messages Msg 156, Level 15, State 1, Line 4 Incorrect syntax near the keyword 'procedure'. I created this example script to illustrate Begin...

Sending one record from cursor to another function Postgres

FYI: I am completely new to using cursors... So I have one function that is a cursor: CREATE FUNCTION get_all_product_promos(refcursor, cursor_object_id integer) RETURNS refcursor AS ' BEGIN OPEN $1 FOR SELECT * FROM promos prom1 JOIN promo_objects ON (prom1.promo_id = promo_objects.promotion_id) ...

How do I change or add data to a data repeater and get it to display in ASP.NET

Here is my code-behind, this adds the "OakTreeName" to the datarepeater. There's about 200 of them. Dim cmd As New SqlClient.SqlCommand("OakTree_Load", New SqlClient.SqlConnection(ConnStr)) cmd.CommandType = CommandType.StoredProcedure cmd.Connection.Open() Dim datareader As SqlClient.SqlDataReader = cmd.ExecuteReader() OakTree_Thumb_R...

Enforcing business rules using a Procedure in Oracle

How do you write a procedure which shows that one field's value cannot be higher than another field's value, in terms of numbers. Say. an employee'a salary can't be higher than his manager's salary. I've never done one before ...