Showing posts with label basic. Show all posts
Showing posts with label basic. Show all posts

Monday, March 19, 2012

How to get status of sp_executesql

Hello

The basic requirement is to import data from excel sheet and save it to a table. The excel filename and sheet name is passed in as a parameter to a stored procedure. I am using sp_executesql to execute the statement.

First I delete all the records from the table and then copy the data from excel into the table. I want to do this as a transaction so that if there is any error in the import process, I want to rollback the transaction otherwise commit it. sp_executesql returns 0 for success or 1 for failure.

In my case, even if there is any syntax error, I get the status of 0. Also the @.@.ROWCOUNT contains some positive number greater than 0 even if some error occurs.

BEGIN TRANSACTION T1

GO

DELETE FROM SORTGROUP

GO

DECLARE @.Statement as NVARCHAR(1024)

DECLARE @.TableName as VARCHAR(32)

DECLARE @.ExcelFile AS VARCHAR(512)

DECLARE @.ParamNameList as VARCHAR(1024)

DECLARE @.SheetName as VARCHAR(64)

DECLARE @.Status as INT

DECLARE @.ErrorCode as INT

DECLARE @.RowCount AS INT

SET @.TableName = 'SORTGROUP'

SET @.ExcelFile = 'E:\PROJECTS\RALEIGH\TEST.XLS'

SET @.ParamNameList = '*'

SET @.SheetName = 'SORTGROUPDATA'

EXEC master..xp_sprintf @.Statement OUTPUT, 'INSERT %s SELECT %s FROM OPENROWSET(''Microsoft.Jet.OLEDB.4.0'', ''Excel 5.0;DATABASE=%s'', ''SELECT %s FROM [%s$]'')', @.TableName, @.ParamNameList, @.ExcelFile, @.ParamNameList, @.SheetName

SET @.Status = -1

exec @.Status=sp_executesql @.Statement

SELECT @.ErrorCode = @.@.ERROR, @.RowCount = @.@.ROWCOUNT

IF @.Status = -1

ROLLBACK TRANSACTION T1

ELSE COMMIT TRANSACTION T1

PRINT @.ErrorCode

PRINT @.RowCount

PRINT @.Status

Is there any reason why you're NOT using DTS to do this? The work flow management will handle all of that for you

How to get started?

This is a repost of my post on the VB Express board.

I would like your opinions.

I am a network guy. I learned basic years ago. I can do some html edits as needed to change sites.

Today I would like to start the long process of learning VB with .net applications. I thought I could start with Office developer xp to learn VB. I have that package.

I also would like to be able to build SQL quaries and integrations or automate and manipulate data exports and imports later down the road.

Example: Export various order and customer information from a shopping cart and import it in to Quickbooks or MS Accounting.

First off I need to be able to build web sites and I know I want to grow into VB and SQL.

What should I do?

Learn HTML from web monkey?

Start with Office xp developer Tutorials?

Start with VB Express?

Buy a book?

Can someone tell me where to start and when to move to the next language?

What is the best resource to get to it, without the bla bla bla and a commnd/syntax refference?

How do I mix Html, CSS and .Net (VB)...in the learning process?

I would like to get the fast track for the long haul.

Thanks so much.

There are a lot of different ways to get started. Think about how you like to learn. Do you like the class environment, informal or structured, do you just like to play with new technology, do you like to read and then apply what you learn.
Here are some suggestions:
* Before you go and buy a bunch of books, go to your local library and see what interests you. Looks for books that give a lot of examples
*Come up with a simple application that you would like to create. Then find examples on how folks have done it already
*Search the internet for examples and samples
* focus on one technology first and then expand
* Purse MCP certification: http://www.microsoft.com/learning/mcpexams/default.mspx
* Download the free editions of products; such as SQL Server Express: http://msdn.microsoft.com/vstudio/express/sql/
There are a lot or resources out there. Check out: http://www.microsoft.com/learning/books/default.mspx. The step-by-step series are great when you are just getting started.
The learning never stops & there is no quick simple solution.
Hope this helps,
Peter Saddow

Friday, March 9, 2012

How to get query execution time of an MS SQL Query in Visual basic

please let me know How to get query execution time of an MS SQL Query
in Visual basic
If you are executing the query from vba, create a timer (using
GetTickcount from the Windows API or something similar). Record the
start time at the beginning of the query, and the stop time after it
completes. Compute the total time elapsed.
--Mary
On 14 Sep 2004 23:46:21 -0700, rajeevmc@.yahoo.com (Rajeev M C) wrote:

>please let me know How to get query execution time of an MS SQL Query
>in Visual basic

How to get query execution time of an MS SQL Query in Visual basic

please let me know How to get query execution time of an MS SQL Query
in Visual basicIf you are executing the query from vba, create a timer (using
GetTickcount from the Windows API or something similar). Record the
start time at the beginning of the query, and the stop time after it
completes. Compute the total time elapsed.
--Mary
On 14 Sep 2004 23:46:21 -0700, rajeevmc@.yahoo.com (Rajeev M C) wrote:
>please let me know How to get query execution time of an MS SQL Query
>in Visual basic