25 April 2009 by findingsteve
It took me a while to finally figured what what went wrong to fix the above error. The problem is my bcp.fmt needs to have an empty line at the last row.

The first screen capture is the one before I added the empty line and the second screen capture is the one after I added the empty line. Take note of the cursor.
After you have added the empty line, it should works.
Posted in SQL / Stored Procedures, SQL Server 2000 | 1 Comment »
2 July 2008 by findingsteve
Let’s try this out. First, open your SQL Query Analyzer. Then, run these three lines of code. (I assume your SQL Server 2000 has default Pubs database).
Use Pubs
SET NOCOUNT ON
SELECT au_lname FROM authors
Then, change from SET NOCOUNT ON to SET NOCOUNT OFF and run them.
Use Pubs
SET NOCOUNT OFF
SELECT au_lname FROM authors
Spot the difference?
Okay, if you didn’t, the hint is at the left bottom tab. Click Messages tab. Got it? The difference is
SET NOCOUNT ON – the count is not returned
SET NOCOUNT OFF – the count is returned
Why we need to set it ON or OFF? Answer is performance. If set it ON, it has a better performance.
Tags: database performance, SET NOCOUNT ON
Posted in SQL / Stored Procedures, SQL Server 2000 | Leave a Comment »
2 July 2008 by findingsteve
You can execute a stored procedure from another stored procedure. This means that you can create a common stored procedure so that any stored procedure which needs this common stored procedure can execute it.
Example, you have these three stored procedures. One is a common one. The other two are normal one.
sp_update
sp_delete
sp_common
Inside sp_update, you have
UPDATE mytable SET status ‘N’
Inside sp_delete, you have
@ID int
AS
DELETE FROM mytable WHERE ID = @ID
Inside sp_common, you have
@ID int,
@desc varchar(3000),
@submit_by varchar(50),
@submit_by varchar(50)
AS
INSERT INTO mytable (id, desc, submitby, submitdt, status)
VALUES (@ID, @desc, @submit_by, @submit_dt, ‘N’)
return 1
If sp_update and sp_delete need sp_common, just add one more line (if there is no return value).
Inside sp_update, add the line in bold
UPDATE mytable SET status ‘N’
EXEC sp_common
Note: You can use either EXEC or EXECUTE. They are the same. But EXEC() is a different thing.
If there is return value, then inside sp_update, add a declaration line and edit the existing execution line (in bold):
DECLARE @status int
UPDATE mytable SET status ‘N’
EXEC @status = sp_common
Tags: EXEC vs EXECUTE vs EXEC()
Posted in SQL / Stored Procedures, SQL Server 2000 | Leave a Comment »