Showing posts with label procedures. Show all posts
Showing posts with label procedures. Show all posts

Wednesday, March 28, 2012

how to save stored procedures on sql express server

Hi Guys

I have visual web developer and sqlexpress 2005 installed on my windows XP pro.

I am creating stored procedures through VWD and works fine for me. However today I realize I do not know how to create stored procedures through sqlexpress server managment.

When I try it it wants to save it as file. And if I do that I am not able to see them until manually open each .sql file.

so, could you enlighten me little please.

thanks
Cemal

hi Cemal,

Cemal wrote:

Hi Guys

I have visual web developer and sqlexpress 2005 installed on my windows XP pro.

I am creating stored procedures through VWD and works fine for me. However today I realize I do not know how to create stored procedures through sqlexpress server managment.

When I try it it wants to save it as file. And if I do that I am not able to see them until manually open each .sql file.

the "disk" button states to actually save the text inside the query window... you can type (or cut&paste) some text, whatever thext in whatever language, and you can later save that text into a file...

when you have to create a stored procedure, you have to execute the data definition language statements defining that object.. so, say you have a text like

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_my_stored_procedure]') AND type in (N'P', N'PC')) DROP PROCEDURE [dbo].[usp_my_stored_procedure]; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[usp_my_stored_procedure] AS BEGIN /**/ /*Author:xxx yyy zzz*/ /*Date:14/07/2007*/ /*Modified:__/__/_*/ /**/ /*Please report suggestions/comments/bugs/feedback to:*/ /*me@.me.com*/ /**/ /* - */ /*this procedure perform these tasks...*/ /**/ DECLARE @.msg varchar(1000); BEGIN TRY SET NOCOUNT ON; SELECT col_list FROM [dbo].[my_table]; RETURN 0; END TRY BEGIN CATCH -- returns the occured exception DECLARE @.ErrorMSG varchar(2000); SET @.ErrorMSG = ERROR_MESSAGE() RAISERROR (@.ErrorMSG, 16, 1); RETURN -100 END CATCH END; GO

you have to execute it in order to "save" it within the database it belongs... to execute it, press the F5 key or the toolbarbutton with the "! Execute" mark...

regards

|||As this is a common misunderstanding, I once did a screencast for that, available on my site:

How to alter a stored procedure within SSMS: Difference between saving and executing a modified stored procedure

Jens K. Suessmeyer.

http://www.sqlserver2005.de

Friday, March 23, 2012

How to run multiple store procedures in SQL Reporting Service

Can we run two store procedures in the Query String under the Dataset section
of SQL Reporting Service 2005? It seems like the Query String only allow one
store procedure. Ww want to use a separate store procedure to open a
symmetric key before we run the second store procedure to retrieve the
sensitive data.What about writing a thrid procedure calling the two others ?
HTH, Jens K. Suessmeyer.
--
http://www.sqlserver2005.de
--sql

Wednesday, March 21, 2012

How to run *.sql ddl automatically

I have tables, views, functions, procedures created in a database with test
data
I would like to be able to automatically kick off the Create sql files via a
script/bat file and bypass having to open all the *sql files in Query
Analyzer.
Can anyone point me to knowledge based articles or How-Tos on this topic?
thx
use copy command to append all files into one, and run osql with -i to input
the file, lastly, schedule osql in a scheduled batch process, or SQL job.
"TroyS" <troy.stauber@.ilg.com> wrote in message
news:uld8QToAGHA.2908@.TK2MSFTNGP10.phx.gbl...
>I have tables, views, functions, procedures created in a database with test
>data
> I would like to be able to automatically kick off the Create sql files via
> a script/bat file and bypass having to open all the *sql files in Query
> Analyzer.
> Can anyone point me to knowledge based articles or How-Tos on this topic?
> thx
>
|||For 2000, use OSQL.EXE. For 2005, use SQLCMD.EXE. To iterate over several files, use FOR in your
batch file:
for %%i in (*.sql) do osql -E -d pubs -STIBWORK\RTM -i %%i
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"TroyS" <troy.stauber@.ilg.com> wrote in message news:uld8QToAGHA.2908@.TK2MSFTNGP10.phx.gbl...
>I have tables, views, functions, procedures created in a database with test data
> I would like to be able to automatically kick off the Create sql files via a script/bat file and
> bypass having to open all the *sql files in Query Analyzer.
> Can anyone point me to knowledge based articles or How-Tos on this topic?
> thx
>
|||thx. i will try the FOR as i have multiple files
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:%237qXfcoAGHA.1460@.TK2MSFTNGP14.phx.gbl...
> For 2000, use OSQL.EXE. For 2005, use SQLCMD.EXE. To iterate over several
> files, use FOR in your batch file:
> for %%i in (*.sql) do osql -E -d pubs -STIBWORK\RTM -i %%i
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "TroyS" <troy.stauber@.ilg.com> wrote in message
> news:uld8QToAGHA.2908@.TK2MSFTNGP10.phx.gbl...
>
|||thx. i'm having a blond moment and had in my mind multiple files to deal
with rather than just paste everything into 1 file.
"Richard Ding" <richard.ding@.monster.com> wrote in message
news:u8RjaYoAGHA.2036@.TK2MSFTNGP14.phx.gbl...
> use copy command to append all files into one, and run osql with -i to
> input the file, lastly, schedule osql in a scheduled batch process, or SQL
> job.
>
> "TroyS" <troy.stauber@.ilg.com> wrote in message
> news:uld8QToAGHA.2908@.TK2MSFTNGP10.phx.gbl...
>

How to run *.sql ddl automatically

I have tables, views, functions, procedures created in a database with test
data
I would like to be able to automatically kick off the Create sql files via a
script/bat file and bypass having to open all the *sql files in Query
Analyzer.
Can anyone point me to knowledge based articles or How-Tos on this topic?
thxuse copy command to append all files into one, and run osql with -i to input
the file, lastly, schedule osql in a scheduled batch process, or SQL job.
"TroyS" <troy.stauber@.ilg.com> wrote in message
news:uld8QToAGHA.2908@.TK2MSFTNGP10.phx.gbl...
>I have tables, views, functions, procedures created in a database with test
>data
> I would like to be able to automatically kick off the Create sql files via
> a script/bat file and bypass having to open all the *sql files in Query
> Analyzer.
> Can anyone point me to knowledge based articles or How-Tos on this topic?
> thx
>|||For 2000, use OSQL.EXE. For 2005, use SQLCMD.EXE. To iterate over several files, use FOR in your
batch file:
for %%i in (*.sql) do osql -E -d pubs -STIBWORK\RTM -i %%i
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"TroyS" <troy.stauber@.ilg.com> wrote in message news:uld8QToAGHA.2908@.TK2MSFTNGP10.phx.gbl...
>I have tables, views, functions, procedures created in a database with test data
> I would like to be able to automatically kick off the Create sql files via a script/bat file and
> bypass having to open all the *sql files in Query Analyzer.
> Can anyone point me to knowledge based articles or How-Tos on this topic?
> thx
>|||thx. i will try the FOR as i have multiple files
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:%237qXfcoAGHA.1460@.TK2MSFTNGP14.phx.gbl...
> For 2000, use OSQL.EXE. For 2005, use SQLCMD.EXE. To iterate over several
> files, use FOR in your batch file:
> for %%i in (*.sql) do osql -E -d pubs -STIBWORK\RTM -i %%i
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "TroyS" <troy.stauber@.ilg.com> wrote in message
> news:uld8QToAGHA.2908@.TK2MSFTNGP10.phx.gbl...
>>I have tables, views, functions, procedures created in a database with
>>test data
>> I would like to be able to automatically kick off the Create sql files
>> via a script/bat file and bypass having to open all the *sql files in
>> Query Analyzer.
>> Can anyone point me to knowledge based articles or How-Tos on this topic?
>> thx
>|||thx. i'm having a blond moment and had in my mind multiple files to deal
with rather than just paste everything into 1 file.
"Richard Ding" <richard.ding@.monster.com> wrote in message
news:u8RjaYoAGHA.2036@.TK2MSFTNGP14.phx.gbl...
> use copy command to append all files into one, and run osql with -i to
> input the file, lastly, schedule osql in a scheduled batch process, or SQL
> job.
>
> "TroyS" <troy.stauber@.ilg.com> wrote in message
> news:uld8QToAGHA.2908@.TK2MSFTNGP10.phx.gbl...
>>I have tables, views, functions, procedures created in a database with
>>test data
>> I would like to be able to automatically kick off the Create sql files
>> via a script/bat file and bypass having to open all the *sql files in
>> Query Analyzer.
>> Can anyone point me to knowledge based articles or How-Tos on this topic?
>> thx
>

How to run *.sql ddl automatically

I have tables, views, functions, procedures created in a database with test
data
I would like to be able to automatically kick off the Create sql files via a
script/bat file and bypass having to open all the *sql files in Query
Analyzer.
Can anyone point me to knowledge based articles or How-Tos on this topic?
thxuse copy command to append all files into one, and run osql with -i to input
the file, lastly, schedule osql in a scheduled batch process, or SQL job.
"TroyS" <troy.stauber@.ilg.com> wrote in message
news:uld8QToAGHA.2908@.TK2MSFTNGP10.phx.gbl...
>I have tables, views, functions, procedures created in a database with test
>data
> I would like to be able to automatically kick off the Create sql files via
> a script/bat file and bypass having to open all the *sql files in Query
> Analyzer.
> Can anyone point me to knowledge based articles or How-Tos on this topic?
> thx
>|||For 2000, use OSQL.EXE. For 2005, use SQLCMD.EXE. To iterate over several fi
les, use FOR in your
batch file:
for %%i in (*.sql) do osql -E -d pubs -STIBWORK\RTM -i %%i
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"TroyS" <troy.stauber@.ilg.com> wrote in message news:uld8QToAGHA.2908@.TK2MSFTNGP10.phx.gbl..
.
>I have tables, views, functions, procedures created in a database with test
data
> I would like to be able to automatically kick off the Create sql files via
a script/bat file and
> bypass having to open all the *sql files in Query Analyzer.
> Can anyone point me to knowledge based articles or How-Tos on this topic?
> thx
>|||thx. i will try the FOR as i have multiple files
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:%237qXfcoAGHA.1460@.TK2MSFTNGP14.phx.gbl...
> For 2000, use OSQL.EXE. For 2005, use SQLCMD.EXE. To iterate over several
> files, use FOR in your batch file:
> for %%i in (*.sql) do osql -E -d pubs -STIBWORK\RTM -i %%i
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "TroyS" <troy.stauber@.ilg.com> wrote in message
> news:uld8QToAGHA.2908@.TK2MSFTNGP10.phx.gbl...
>|||thx. i'm having a blond moment and had in my mind multiple files to deal
with rather than just paste everything into 1 file.
"Richard Ding" <richard.ding@.monster.com> wrote in message
news:u8RjaYoAGHA.2036@.TK2MSFTNGP14.phx.gbl...
> use copy command to append all files into one, and run osql with -i to
> input the file, lastly, schedule osql in a scheduled batch process, or SQL
> job.
>
> "TroyS" <troy.stauber@.ilg.com> wrote in message
> news:uld8QToAGHA.2908@.TK2MSFTNGP10.phx.gbl...
>

Monday, March 19, 2012

How to rollback properly

Hi,
suppose I've got 3 stored procedures: P1, P2, P3. I would like to run them
in some order and roll back the whole series of actions if an error occurs
in any of them. (Basically I would like to achieve the same effect as things
happen in an Oracle environment.) So:
BEGIN TRANSACTION tran_1
EXEC P1;
EXEC P2;
EXEC P3;
IF [there was an error somewhere] -- how?
ROLLBACK TRANSACTION tran_1
ELSE
COMMIT TRANSACTION tran_1
So, what is the proper way to produce this behavior?Agostan,
I would handle this situation by testing the error status of each of the
procedures using a return code. The following code fragment would sit after
each SQL statement in the procedure:
IF @.@.ERROR <> 0
BEGIN
RETURN 1
END
You would also need to include a return code at the end of the procedure for
successful completion:
RETURN 0
Then your procedure calls would need to collect this return code into a
variable and and test the result:
EXEC @.RC1 = P1
EXEC @.RC2 = P2
EXEC @.RC3 = P3
The convention I use is to have a positive non-zero return code for failure
and a zero return code for success, so to test for success or failure in your
example I would use:
IF @.RC1 + @.RC2 + @.RC3 > 0
BEGIN...etc
Hope this helps,
"Agoston Bejo" wrote:
> Hi,
> suppose I've got 3 stored procedures: P1, P2, P3. I would like to run them
> in some order and roll back the whole series of actions if an error occurs
> in any of them. (Basically I would like to achieve the same effect as things
> happen in an Oracle environment.) So:
> BEGIN TRANSACTION tran_1
> EXEC P1;
> EXEC P2;
> EXEC P3;
> IF [there was an error somewhere] -- how?
> ROLLBACK TRANSACTION tran_1
> ELSE
> COMMIT TRANSACTION tran_1
> So, what is the proper way to produce this behavior?
>
>|||You has to check @.@.ERROR and grab also the return value from the sps.
Implementing Error Handling with Stored Procedures
http://www.sommarskog.se/error-handling-II.html
Error Handling in SQL Server â' a Background
http://www.sommarskog.se/error-handling-I.html
AMB
"Agoston Bejo" wrote:
> Hi,
> suppose I've got 3 stored procedures: P1, P2, P3. I would like to run them
> in some order and roll back the whole series of actions if an error occurs
> in any of them. (Basically I would like to achieve the same effect as things
> happen in an Oracle environment.) So:
> BEGIN TRANSACTION tran_1
> EXEC P1;
> EXEC P2;
> EXEC P3;
> IF [there was an error somewhere] -- how?
> ROLLBACK TRANSACTION tran_1
> ELSE
> COMMIT TRANSACTION tran_1
> So, what is the proper way to produce this behavior?
>
>

How to rollback properly

Hi,
suppose I've got 3 stored procedures: P1, P2, P3. I would like to run them
in some order and roll back the whole series of actions if an error occurs
in any of them. (Basically I would like to achieve the same effect as things
happen in an Oracle environment.) So:
BEGIN TRANSACTION tran_1
EXEC P1;
EXEC P2;
EXEC P3;
IF [there was an error somewhere] -- how?
ROLLBACK TRANSACTION tran_1
ELSE
COMMIT TRANSACTION tran_1
So, what is the proper way to produce this behavior?Agostan,
I would handle this situation by testing the error status of each of the
procedures using a return code. The following code fragment would sit after
each SQL statement in the procedure:
IF @.@.ERROR <> 0
BEGIN
RETURN 1
END
You would also need to include a return code at the end of the procedure for
successful completion:
RETURN 0
Then your procedure calls would need to collect this return code into a
variable and and test the result:
EXEC @.RC1 = P1
EXEC @.RC2 = P2
EXEC @.RC3 = P3
The convention I use is to have a positive non-zero return code for failure
and a zero return code for success, so to test for success or failure in you
r
example I would use:
IF @.RC1 + @.RC2 + @.RC3 > 0
BEGIN...etc
Hope this helps,
"Agoston Bejo" wrote:

> Hi,
> suppose I've got 3 stored procedures: P1, P2, P3. I would like to run them
> in some order and roll back the whole series of actions if an error occurs
> in any of them. (Basically I would like to achieve the same effect as thin
gs
> happen in an Oracle environment.) So:
> BEGIN TRANSACTION tran_1
> EXEC P1;
> EXEC P2;
> EXEC P3;
> IF [there was an error somewhere] -- how?
> ROLLBACK TRANSACTION tran_1
> ELSE
> COMMIT TRANSACTION tran_1
> So, what is the proper way to produce this behavior?
>
>|||You has to check @.@.ERROR and grab also the return value from the sps.
Implementing Error Handling with Stored Procedures
http://www.sommarskog.se/error-handling-II.html
Error Handling in SQL Server – a Background
http://www.sommarskog.se/error-handling-I.html
AMB
"Agoston Bejo" wrote:

> Hi,
> suppose I've got 3 stored procedures: P1, P2, P3. I would like to run them
> in some order and roll back the whole series of actions if an error occurs
> in any of them. (Basically I would like to achieve the same effect as thin
gs
> happen in an Oracle environment.) So:
> BEGIN TRANSACTION tran_1
> EXEC P1;
> EXEC P2;
> EXEC P3;
> IF [there was an error somewhere] -- how?
> ROLLBACK TRANSACTION tran_1
> ELSE
> COMMIT TRANSACTION tran_1
> So, what is the proper way to produce this behavior?
>
>

How to rollback properly

Hi,
suppose I've got 3 stored procedures: P1, P2, P3. I would like to run them
in some order and roll back the whole series of actions if an error occurs
in any of them. (Basically I would like to achieve the same effect as things
happen in an Oracle environment.) So:
BEGIN TRANSACTION tran_1
EXEC P1;
EXEC P2;
EXEC P3;
IF [there was an error somewhere] -- how?
ROLLBACK TRANSACTION tran_1
ELSE
COMMIT TRANSACTION tran_1
So, what is the proper way to produce this behavior?
Agostan,
I would handle this situation by testing the error status of each of the
procedures using a return code. The following code fragment would sit after
each SQL statement in the procedure:
IF @.@.ERROR <> 0
BEGIN
RETURN 1
END
You would also need to include a return code at the end of the procedure for
successful completion:
RETURN 0
Then your procedure calls would need to collect this return code into a
variable and and test the result:
EXEC @.RC1 = P1
EXEC @.RC2 = P2
EXEC @.RC3 = P3
The convention I use is to have a positive non-zero return code for failure
and a zero return code for success, so to test for success or failure in your
example I would use:
IF @.RC1 + @.RC2 + @.RC3 > 0
BEGIN...etc
Hope this helps,
"Agoston Bejo" wrote:

> Hi,
> suppose I've got 3 stored procedures: P1, P2, P3. I would like to run them
> in some order and roll back the whole series of actions if an error occurs
> in any of them. (Basically I would like to achieve the same effect as things
> happen in an Oracle environment.) So:
> BEGIN TRANSACTION tran_1
> EXEC P1;
> EXEC P2;
> EXEC P3;
> IF [there was an error somewhere] -- how?
> ROLLBACK TRANSACTION tran_1
> ELSE
> COMMIT TRANSACTION tran_1
> So, what is the proper way to produce this behavior?
>
>
|||You has to check @.@.ERROR and grab also the return value from the sps.
Implementing Error Handling with Stored Procedures
http://www.sommarskog.se/error-handling-II.html
Error Handling in SQL Server – a Background
http://www.sommarskog.se/error-handling-I.html
AMB
"Agoston Bejo" wrote:

> Hi,
> suppose I've got 3 stored procedures: P1, P2, P3. I would like to run them
> in some order and roll back the whole series of actions if an error occurs
> in any of them. (Basically I would like to achieve the same effect as things
> happen in an Oracle environment.) So:
> BEGIN TRANSACTION tran_1
> EXEC P1;
> EXEC P2;
> EXEC P3;
> IF [there was an error somewhere] -- how?
> ROLLBACK TRANSACTION tran_1
> ELSE
> COMMIT TRANSACTION tran_1
> So, what is the proper way to produce this behavior?
>
>

Monday, March 12, 2012

How to return multiple values from stored procedures

How to return multiple values from stored procedures to reports in sql server 2005

Hello,

Do you mean multiple resultsets from a single stored procedure? This is not supported, Reporting Services will only use the first one. You could break up your stored procedure so that each resultset would populate it's own dataset in the report.

Hope this helps.

Jarret

|||Not possible, one resultset only.

Jens K. Suessmeyer.

http://www.sqlserver2005.de

|||thanx

How to return an entire table using store procedure

hi all

this is my 2nd post and it's in relation to how to make store procedures return an entire table to a application. i am using .NET as my application development platform.

I know how parameters can be passed in and out of store procedures, but this returns single value parameters.

when plain SQL select statements are executed against the database as nonqueries through the ADO/ADO.NET API, an entire recordset/dataset can be returned.

But when i put the select statements in a store procedure, how do i make the select statement return an entire recordset/dataset back to the calling application?

thanks for taking your time to read.

Cheers

jOriginally posted by nano_electronix
hi all

this is my 2nd post and it's in relation to how to make store procedures return an entire table to a application. i am using .NET as my application development platform.

I know how parameters can be passed in and out of store procedures, but this returns single value parameters.

when plain SQL select statements are executed against the database as nonqueries through the ADO/ADO.NET API, an entire recordset/dataset can be returned.

But when i put the select statements in a store procedure, how do i make the select statement return an entire recordset/dataset back to the calling application?

thanks for taking your time to read.

Cheers

j

Hi, maybe I did not understand your problem entirely, but a stored procedure returning a recordset is as simple as

create procedure P as select * from sales
go

exec p
go

Hope, this helps.|||but wat happens when there are multiple select statements

how do you retrieve the results of a store procedure that has multiple select statements which would return multiple tables, which means multiple recordsets in the case of asp

besides given the store procedure you shown there, how would you get it into a recordset/dataset using either asp or asp.net.

for example, in asp.net i make use of dataadapter to retrieve a table into a dataset (which can store multiple table) but if i use store procedure i am not sure how that can be done.

cheers

j|||i think i might know why you don't understand my problem

the sql command that you gave is correct and will return a table of results if it is executed within the query analyser.

wat i am talking about is how would i retrieve the table of results if i were to use the store procedure within an application, how would i retrieve those results into a recordset/dataset (ASP/ASP.NET)

when i want to execute a storeprocedure using ms .net, wat i have to do is use a oledbcommand and make it of type storeprocedure and then execute it as a nonquery, but i have no idea how the result may be returned to the application when the oledbcommand is executed as a nonquery. i've tried to execute the oledbcommand as a reader rather than a nonquery, but that gave me exception when i tried to read data off the datareader that is returned (i don't think that's the way to do it anyhow).

I am sure someone would have run across a time when an application need to use a store procedure to execute a batch of sql commands and at the same time returns results to the application as a table of data.

if i can't do this, the only way that i could achieve the same effect is by creating temporary table and then execute an extra select statement to retrieve the data from the temporary table, this would be quite wasteful.

Please help

J|||Hi

Executing SP which will return a record set within .Net is straight forward. By the way for SQL2000 you should use SQLClient name space functions instead of OleDB for performance reason more then anything.

Use the SQLCommand.ExecuteReader and set the commandtext to the stored procedure and parameters and commandtype = CommandType.StoredProcedure. I enclosed the example from MSDN below for SQL. If you do need OleDB then just change the Sql to OleDb.

Regards

Richard...

SqlConnection nwindConn = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind");

SqlCommand salesCMD = new SqlCommand("SalesByCategory", nwindConn);
salesCMD.CommandType = CommandType.StoredProcedure;

SqlParameter myParm = salesCMD.Parameters.Add("@.CategoryName", SqlDbType.NVarChar, 15);
myParm.Value = "Beverages";

nwindConn.Open();

SqlDataReader myReader = salesCMD.ExecuteReader();

Console.WriteLine("{0}, {1}", myReader.GetName(0), myReader.GetName(1));

while (myReader.Read())
{
Console.WriteLine("{0}, ${1}", myReader.GetString(0), myReader.GetDecimal(1));
}

myReader.Close();
nwindConn.Close();|||I had the same problem about a month ago. I think what you're looking for is the datareader. Here's an example of how it works:

Dim connection As New SqlConnection()
Dim cmdSelect As SqlCommand
Dim reader As SqlDataReader
Dim Num As Integer

Num = 12
connection = SqlConnection1

cmdSelect = New SqlCommand("exec sp_getNum @.date = " & Num), connection)
If connection.State <> ConnectionState.Open Then connection.Open()
reader = cmdSelect.ExecuteReader
datalist.DataSource = reader
datalist.DataBind()
reader.Close()
connection.Close()

If you need more tables, just created more readers. Is that what you're looking for?|||Originally posted by nano_electronix
but wat happens when there are multiple select statements

how do you retrieve the results of a store procedure that has multiple select statements which would return multiple tables, which means multiple recordsets in the case of asp
j

I would guess you would want to have one select statement per sproc. and then create a recordset for each executed sproc?|||thanx guys

I'll try the datareader again, but i have tried it exactly the same way as the sample code above, but like i said it gave me exception, i'll give it another try and get back to you guys, hope it work.

Originally posted by nano_electronix

i've tried to execute the oledbcommand as a reader rather than a nonquery, but that gave me exception when i tried to read data off the datareader that is returned (i don't think that's the way to do it anyhow).

J|||hi guys

first of all thanx for very much for all your help. i will sure to come back to this forum for more help later.

i found out where the problem was, it was a datatype conversion problem that gave me the exception, it wasn't the datareader that gave me the exception, i didn't check the exception carefully.

i am using oledb over the managed sql components because i want to try to make this application crossplatform for all databases, i haven't had a chance to try oracle yet, but that's where i am heading.

cheers :)

j

How to return a Table with Stored Procedures?

i have a procedure like below but it dosen't return any table

SELECT Hardwares.HWID, Hardwares.TitleFROM HardwaresINNERJOIN CategoryON Hardwares.CategoryID = Category.CategoryIDWHERE (Category.TypeLIKE'%Hardware%')AND (Category.Title = @.Title)

Without more information, my guess is that there are no rows in the table Hardwares which meet your where criteria.

Can you post a sample row which you would expect to be returned using this query? Also, what are you passing in for the @.Title parameter.

|||

The output of a SELECT query is always tabular. If you run this query in your query analyzer / management studio, what results do you see? How are you executing this stored procedure from within your data access code?

Matt

|||

i actually missed out the varchar(n) part. so it becomes only 1 character

Friday, March 9, 2012

How to Retrive Dropped Procedures in SQL Server

Hi,
I had dropped a stored procedure from SQL Server DB.
Please let me know if there is any way retrive the dropped
procedures?
Please help me in finding the solution.
thanks,
athmaram
Well, do you ever take database backups? Do you ever store your procedure
code in source control of any kind? Keep local copies, even? How about the
same procedures from dev/test/staging environments?
Aaron Bertrand
SQL Server MVP
http://www.sqlblog.com/
http://www.aspfaq.com/5006
"Athmaram" <athmaramp@.gmail.com> wrote in message
news:1182814933.762281.75850@.e16g2000pri.googlegro ups.com...
> Hi,
> I had dropped a stored procedure from SQL Server DB.
>
> Please let me know if there is any way retrive the dropped
> procedures?
>
> Please help me in finding the solution.
>
> thanks,
> athmaram
>
|||Hello,
If you have a production staging or QA environment and if the procedure
version is same then pick from there. Or else restore the last days database
backup
with a new name and pick the procedure from there and create it in the
actual database.
Thanks
Hari
"Athmaram" <athmaramp@.gmail.com> wrote in message
news:1182814933.762281.75850@.e16g2000pri.googlegro ups.com...
> Hi,
> I had dropped a stored procedure from SQL Server DB.
>
> Please let me know if there is any way retrive the dropped
> procedures?
>
> Please help me in finding the solution.
>
> thanks,
> athmaram
>

How to Retrive Dropped Procedures in SQL Server

Hi,
I had dropped a stored procedure from SQL Server DB.
Please let me know if there is any way retrive the dropped
procedures?
Please help me in finding the solution.
thanks,
athmaramWell, do you ever take database backups? Do you ever store your procedure
code in source control of any kind? Keep local copies, even? How about the
same procedures from dev/test/staging environments?
Aaron Bertrand
SQL Server MVP
http://www.sqlblog.com/
http://www.aspfaq.com/5006
"Athmaram" <athmaramp@.gmail.com> wrote in message
news:1182814933.762281.75850@.e16g2000pri.googlegroups.com...
> Hi,
> I had dropped a stored procedure from SQL Server DB.
>
> Please let me know if there is any way retrive the dropped
> procedures?
>
> Please help me in finding the solution.
>
> thanks,
> athmaram
>|||Hello,
If you have a production staging or QA environment and if the procedure
version is same then pick from there. Or else restore the last days database
backup
with a new name and pick the procedure from there and create it in the
actual database.
Thanks
Hari
"Athmaram" <athmaramp@.gmail.com> wrote in message
news:1182814933.762281.75850@.e16g2000pri.googlegroups.com...
> Hi,
> I had dropped a stored procedure from SQL Server DB.
>
> Please let me know if there is any way retrive the dropped
> procedures?
>
> Please help me in finding the solution.
>
> thanks,
> athmaram
>

How to Retrive Dropped Procedures in SQL Server

Hi,
I had dropped a stored procedure from SQL Server DB.
Please let me know if there is any way retrive the dropped
procedures?
Please help me in finding the solution.
thanks,
athmaramWell, do you ever take database backups? Do you ever store your procedure
code in source control of any kind? Keep local copies, even? How about the
same procedures from dev/test/staging environments?
--
Aaron Bertrand
SQL Server MVP
http://www.sqlblog.com/
http://www.aspfaq.com/5006
"Athmaram" <athmaramp@.gmail.com> wrote in message
news:1182814933.762281.75850@.e16g2000pri.googlegroups.com...
> Hi,
> I had dropped a stored procedure from SQL Server DB.
>
> Please let me know if there is any way retrive the dropped
> procedures?
>
> Please help me in finding the solution.
>
> thanks,
> athmaram
>|||Hello,
If you have a production staging or QA environment and if the procedure
version is same then pick from there. Or else restore the last days database
backup
with a new name and pick the procedure from there and create it in the
actual database.
Thanks
Hari
"Athmaram" <athmaramp@.gmail.com> wrote in message
news:1182814933.762281.75850@.e16g2000pri.googlegroups.com...
> Hi,
> I had dropped a stored procedure from SQL Server DB.
>
> Please let me know if there is any way retrive the dropped
> procedures?
>
> Please help me in finding the solution.
>
> thanks,
> athmaram
>