Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 [Resolved] Ansi_Nulls in strored procedure

Author  Topic 

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2009-02-06 : 12:36:14
I read below (http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_20629811.html)

You can set ANSI options when you create the stored procedure...these will be inherited...

SET ANSI_NULLS ON
SET ANSI_WARNINGS ON

CREATE PROCEDURE MyProc as

Select * from [LinkedServer].DBname.dbo.Mytable

So when I try create my proc:

SET ANSI_NULLS OFF
SET ANSI_WARNINGS OFF

CREATE PROCEDURE dbo.sp_ZyTax_Import

(
@RetValue char(50),
@Library nvarchar(10),
@File nvarchar(10),
@Member nvarchar(10),
@rc int output
)

AS

SET NOCOUNT ON

Exec ('Call QGPL.sp_ovrdbf(?,?,?,?)', @Library, @File, @Member, @rc) AT AS400SRV_IBMDASQL


I get error

Msg 111, Level 15, State 1, Procedure sp_ZyTax_Import, Line 19
'CREATE/ALTER PROCEDURE' must be the first statement in a query batch.

revdnrdy
Posting Yak Master

220 Posts

Posted - 2009-02-06 : 12:45:18
quote:
Originally posted by snufse

I read below (http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_20629811.html)

You can set ANSI options when you create the stored procedure...these will be inherited...

SET ANSI_NULLS ON
GO
SET ANSI_WARNINGS ON
GO
CREATE PROCEDURE MyProc as

Select * from [LinkedServer].DBname.dbo.Mytable

So when I try create my proc:

SET ANSI_NULLS OFF
SET ANSI_WARNINGS OFF

CREATE PROCEDURE dbo.sp_ZyTax_Import

(
@RetValue char(50),
@Library nvarchar(10),
@File nvarchar(10),
@Member nvarchar(10),
@rc int output
)

AS

SET NOCOUNT ON

Exec ('Call QGPL.sp_ovrdbf(?,?,?,?)', @Library, @File, @Member, @rc) AT AS400SRV_IBMDASQL


I get error

Msg 111, Level 15, State 1, Procedure sp_ZyTax_Import, Line 19
'CREATE/ALTER PROCEDURE' must be the first statement in a query batch.



Try what I posted in red.. I also encourage you to read up on the GO syntax which separates your code into batches (so to speak).

r&r
Go to Top of Page

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2009-02-06 : 13:16:42
Purrrfect, thank you.
Go to Top of Page
   

- Advertisement -