stored-procedures

How to make a return type for a result set in LINQ

I am having a problem determining how c# and LINQ solve the common problem of handling a data structure that does not necessarily return a table structure, but instead a resultset. I have a stored procedure that works, and have included it in my DBML [Function(Name="dbo.p_GetObject")] public int p_GetObject([Parameter(Name="ObjectType"...

MS SQL SP - Working with EXEC recordset

Is there a way to work on a recordset returned from an exec within another SP? The whole recordset, preferably not using OUTPUT I.E. MyStoredProcedure @var1 int AS BEGIN EXEC anotherSP @var1 -- do something against the recordset returned by anotherSP END ...

ASP (not .NET): sending null as parameter to stored procedure in query string?

I have the following code on an ASP page: <% QueryToJSON(conn, "execute WebGetEmployeesPlanned'" +Request.QueryString("customercode")+"', '"+Request.QueryString("lang")+"', '"+Request.QueryString("date")+"'").flush %> There is no other code on this page except some includes, as I call this page with ajax from another...

What's the optimal solution for tag/keyword matching?

I'm looking for the optimal solution for keyword matching between different records in the database. It's a classic problem, I've found similar questions, but nothing concretely. I've done it with full text searches, joins and subqueries, temp tables, ... so i'd really like to see how you guys are solving such a common problem. So, let...

What's your favored method for debugging MS SQL stored procedures?

Most of my SPs can simply be executed (and tested) with data entered manually. This works well and using simple PRINT statements allows me to "debug". There are however cases where more than one stored procedure is involved and finding valid data to input is tedious. It's easier to just trigger things from within my web app. I have a...

Passing an "in" list via stored procedure...

Duplicate of: http://stackoverflow.com/questions/43249/t-sql-stored-procedure-that-accepts-multiple-id-values/43767#43767 How can I construct a stored procedure that will allow me to pass (for example) an @IDList so that I can write: Select * from Foo Where ID in @IDList Is this doable? TIA! Kevin ...

When to do stored procedures and when not to

This is just a general discussion on what is the best occasion to use stored procedure! Personnally i have very low opinion on stored procs becouse; 1. they tie you to one particular database enviroment and 2. the idea of shuffling back and fourth between your interface code and the back-end enviroment for the stored procs its a nightmar...

Should transactions be specified outside a stored procedure or inside?

We can wrap a call to a stored procedure in a transaction and specify an isolation level. Or we can put the transaction inside the stored procedure specify an isolation level there. Which is it better to do? ...

SQL Server 2005 Full Text forum Search

I'm working on a search stored procedure for our existing forums. I've written the following code which uses standard SQL full text indexes, however I'm sure there is a better way of doing it and would like a point in the right direction. To give some info on how it needs to work, The page has 1 search text box which when clicked will ...

Is it possible to pass db name as a parameter

I have about 100 sites built in a cms, each with its own database. Each database has the same tables. My stored procedure needs to select all of the pages in a database given a sitename. Below I am trying to pass the database name as a parameter, but it doesn't seem to work. ... @site nvarchar(250) AS SELECT * FROM @site..cmsDocumen...

Best way to learn PostgreSQL stored procedures?

Is there a good tutorial or something similar for learning how to write Stored Procedures (for a PostgreSQL database). I'm a definite newbie when it comes to writing Stored Procedures at all, so the clearer and simpler things are explained, the better... Thanks in advance... ...

Are there any gotchas or good reasons not to use autosproc for stored procedure calls?

I've implemented a data access layer that populates generic entities from a datareader using a variation of the third monkey approach (http://www.codeproject.com/KB/database/DynamicMethod_ILGenerator.aspx). This works well, performs well and saves me writing loads of repetetive code for data retrieval. Now I want to add methods that tak...

How to simulate the Print function in a MySQL Stored Procedure

I'm creating a MySQL Stored Procedure with a few cursors. I want to make sure the Insert/Update statements it will ultimately generate are correct before making it live. I searched and could not find a PRINT or similar method to have it just send output back to the client, in my case SQLyog Enterprise. I tried declaring a variable as T...

How should I optimize multiple calls in my .net code to a trivial stored procedure ?

I've got a very simple stored procedure : create procedure spFoo(v varchar(50)) as insert into tbFoo select v I've got 50 values to insert into tbFoo, which means in my c# code I call spFoo 50 times. This is a pretty inefficient way of doing this, especially if there's some lag between my program and the database. What do you usuall...

Best way to send an array of values to a stored proc

Should I use a CSV string, an XML string or...? ...

Oracle stored procedures, SYS_REFCURSOR and NHibernate

I have a legacy Oracle (10.2g) database that I'm connecting to and I'd like to use NHibernate (2.0.1) to give me back objects from a stored procedure. The stored procedure in question uses a SYS_REFCURSOR to return results. According to the documentation this should be doable but I've found a few posts on the internet that suggest otherw...

SQL syntax error when creating a stored procedure in MYSQL

hi all, i have a hard time locating an error when trying to create a stored procedure in mysql. if i run every single line of the procedure independently, everything works just fine. CREATE PROCEDURE cms_proc_add_child (param_parent_id INT, param_name CHAR(255), param_content_type CHAR(255)) BEGIN SELECT @child_left := rgt FROM cm...

TSQL Check if a row exists, otherwise insert

Hi. I need to write a T-SQL stored procedure that updates a row in a table. If the row doesn't exist, insert it. All this steps wrapped by a transaction. This is for a booking system, so it must be atomic and reliable. It must return true if the transaction was commited and the flight booked. I'm new to T-SQL, and not sure on how to u...

access LAST_INSERT_ID() from php after calling a stored procedure

hi all, i have defined a stored procedure (let's call it proc_create_node(parent INT)) in mysql which does an insertion. when i call it from the mysql cli, doing the following works just fine: CALL proc_create_node(12); SELECT LAST_INSERT_ID(); and i get the last inserted id: +------------------+ | LAST_INSERT_ID() | +-------------...

How to pass a Nullable<int> into a stored procedure... from F#?

I'm trying to call a stored procedure with an output parameter from F#, so I need to pass an int? value initialized to null. However, F# is resisting my attempts, saying that the object cannot be null. I've read up on the web as to why that is but my problem remains - I need to call that stored procedure. Has anyone got any ideas as to h...