Showing posts with label procedure. Show all posts
Showing posts with label procedure. Show all posts

Friday, March 30, 2012

Not a valid identifier while executing an Stored procedure

Hey

I have written the following the stored procedure and executed it.But i am getting the following error. I don't know the reason for this.

setANSI_NULLSON

setQUOTED_IDENTIFIERON

go

Create PROCEDURE [dbo].[GSU_Site_ReterieveActiveSitesOnSearch]

@.whereClause nvarchar(2000)

AS

BEGIN

-- SET NOCOUNT ON added to prevent extra result sets from

-- interfering with SELECT statements.

declare @.sqlstr asvarchar(max)

set @.sqlstr='SELECT Site.siteid as siteid,'

set @.sqlstr=@.sqlstr+'Site.Sitename as sitename, '

set @.sqlstr= @.sqlstr+'Customer.customerid,'

set @.sqlstr= @.sqlstr+'Customer.customername as CustomerName,'

set @.sqlstr= @.sqlstr+'Site.City as City,'

set @.sqlstr= @.sqlstr+'site.Address as Address,'

set @.sqlstr =@.sqlstr+'Site.state , '

set @.sqlstr= @.sqlstr+'Country.countryid as countryid,'

set @.sqlstr= @.sqlstr+'Country.countryname as country,Businessunit.businessunitid ,businessunit.businessunitname as BUName,'

set @.sqlstr= @.sqlstr+'SystemType.SystemTypeID,SystemType.SystemTypeName FROM Site INNER JOIN Country '

set @.sqlstr= @.sqlstr+'ON Country.countryid = Site.countryid INNER JOIN Customer ON Customer.customerid=Site.customerid '

set @.sqlstr= @.sqlstr+'INNER JOIN Businessunit ON Businessunit.businessunitID=Site.BusinessUnitID INNER JOIN SystemType ON '

set @.sqlstr= @.sqlstr+'SystemType.SystemTypeID=Site.SystemTypeID INNER JOIN GSUStatus ON Site.GSUStatusID=GSUStatus.GSUStatusID '

set @.sqlstr= @.sqlstr+@.whereClause

--

--set @.sqlstr=@.sqlstr+' WHERE GSUStatus.GSUStatusID=' +@.GSUStatusID

--if @.BusinessUnitID <> 0

--set @.sqlstr=@.sqlstr+'and site.BusinessUnitID ='+@.BusinessUnitID

--if @.CountryID <> 0

--set @.sqlstr=@.sqlstr+'and site.countryid='+@.CountryID

--if @.CustomerID <> 0

--set @.sqlstr=@.sqlstr+'and site.customerid='+@.CustomerID

--if @.SystemTypeID <> 0

--set @.sqlstr=@.sqlstr+'and site.SystemTypeID='+@.SystemTypeID

--if @.SiteName <> ''

--set @.sqlstr=@.sqlstr+'and site.Sitename like ' + @.SiteName

--if @.Address <> ''

--set @.sqlstr=@.sqlstr+'site.Address like '+ @.Address

--if @.City <> ''

--set @.sqlstr=@.sqlstr+'site.City like '+ @.City

--if @.State <> ''

--set @.sqlstr=@.sqlstr+'and site.state like '+ @.State

print @.sqlstr

exec @.sqlstr

END

I executed the procedure by pasing parameters

Exec [GSU_Site_ReterieveActiveSitesOnSearch]

" where GSUStatus.GSUStatusID=1 and site.Sitename like 'lakshmisite' "

and getting the following error

- exc {"The name 'SELECT Site.siteid as siteid,Site.Sitename as sitename, Customer.customerid,Customer.customername as CustomerName,Site.City as City,site.Address as Address,Site.state , Country.countryid as countryid,Country.countryname as country,Businessunit.businessunitid ,businessunit.businessunitname as BUName,SystemType.SystemTypeID,SystemType.SystemTypeName FROM Site INNER JOIN Country ON Country.countryid = Site.countryid INNER JOIN Customer ON Customer.customerid=Site.customerid INNER JOIN Businessunit ON Businessunit.businessunitID=Site.BusinessUnitID INNER JOIN SystemType ON SystemType.SystemTypeID=Site.SystemTypeID INNER JOIN GSUStatus ON S' is not a valid identifier."} System.Exception {System.Data.SqlClient.SqlException}

Please let me know the problem in this.

Thanks

Kusuma

Hey

I have written the following the stored procedure and executed it.But i am getting the following error. I don't know the reason for this.

setANSI_NULLSON

setQUOTED_IDENTIFIERON

go

Create PROCEDURE [dbo].[GSU_Site_ReterieveActiveSitesOnSearch]

@.whereClause nvarchar(2000)

AS

BEGIN

-- SET NOCOUNT ON added to prevent extra result sets from

-- interfering with SELECT statements.

declare @.sqlstr asvarchar(max)

set @.sqlstr='SELECT Site.siteid as siteid,'

set @.sqlstr=@.sqlstr+'Site.Sitename as sitename, '

set @.sqlstr= @.sqlstr+'Customer.customerid,'

set @.sqlstr= @.sqlstr+'Customer.customername as CustomerName,'

set @.sqlstr= @.sqlstr+'Site.City as City,'

set @.sqlstr= @.sqlstr+'site.Address as Address,'

set @.sqlstr =@.sqlstr+'Site.state , '

set @.sqlstr= @.sqlstr+'Country.countryid as countryid,'

set @.sqlstr= @.sqlstr+'Country.countryname as country,Businessunit.businessunitid ,businessunit.businessunitname as BUName,'

set @.sqlstr= @.sqlstr+'SystemType.SystemTypeID,SystemType.SystemTypeName FROM Site INNER JOIN Country '

set @.sqlstr= @.sqlstr+'ON Country.countryid = Site.countryid INNER JOIN Customer ON Customer.customerid=Site.customerid '

set @.sqlstr= @.sqlstr+'INNER JOIN Businessunit ON Businessunit.businessunitID=Site.BusinessUnitID INNER JOIN SystemType ON '

set @.sqlstr= @.sqlstr+'SystemType.SystemTypeID=Site.SystemTypeID INNER JOIN GSUStatus ON Site.GSUStatusID=GSUStatus.GSUStatusID '

set @.sqlstr= @.sqlstr+@.whereClause

--

--set @.sqlstr=@.sqlstr+' WHERE GSUStatus.GSUStatusID=' +@.GSUStatusID

--if @.BusinessUnitID <> 0

--set @.sqlstr=@.sqlstr+'and site.BusinessUnitID ='+@.BusinessUnitID

--if @.CountryID <> 0

--set @.sqlstr=@.sqlstr+'and site.countryid='+@.CountryID

--if @.CustomerID <> 0

--set @.sqlstr=@.sqlstr+'and site.customerid='+@.CustomerID

--if @.SystemTypeID <> 0

--set @.sqlstr=@.sqlstr+'and site.SystemTypeID='+@.SystemTypeID

--if @.SiteName <> ''

--set @.sqlstr=@.sqlstr+'and site.Sitename like ' + @.SiteName

--if @.Address <> ''

--set @.sqlstr=@.sqlstr+'site.Address like '+ @.Address

--if @.City <> ''

--set @.sqlstr=@.sqlstr+'site.City like '+ @.City

--if @.State <> ''

--set @.sqlstr=@.sqlstr+'and site.state like '+ @.State

print @.sqlstr

exec @.sqlstr

END

I executed the procedure by pasing parameters

Exec [GSU_Site_ReterieveActiveSitesOnSearch]

" where GSUStatus.GSUStatusID=1 and site.Sitename like 'lakshmisite' "

and getting the following error

- exc {"The name 'SELECT Site.siteid as siteid,Site.Sitename as sitename, Customer.customerid,Customer.customername as CustomerName,Site.City as City,site.Address as Address,Site.state , Country.countryid as countryid,Country.countryname as country,Businessunit.businessunitid ,businessunit.businessunitname as BUName,SystemType.SystemTypeID,SystemType.SystemTypeName FROM Site INNER JOIN Country ON Country.countryid = Site.countryid INNER JOIN Customer ON Customer.customerid=Site.customerid INNER JOIN Businessunit ON Businessunit.businessunitID=Site.BusinessUnitID INNER JOIN SystemType ON SystemType.SystemTypeID=Site.SystemTypeID INNER JOIN GSUStatus ON S' is not a valid identifier."} System.Exception {System.Data.SqlClient.SqlException}

Please let me know the problem in this.

Thanks

Kusuma

|||

First off, I'm not sure why you're constructing a dynamic select inside your procedure...the procedure should be the select statement, using any input parameters you defined.

But to solve the problem, you need to change

exec @.sqlstr

to

exec(@.sqlstr)

I'd rewrite the entire piece of code...

|||

This is a duplicate post.

Please see answer in your other posting.

|||

Use the following satement to execute the SP,

Code Snippet

Exec [GSU_Site_ReterieveActiveSitesOnSearch]' where GSUStatus.GSUStatusID=1and site.Sitename like''lakshmisite'' '

|||

Kusuma,

Instead passing the this value " where GSUStatus.GSUStatusID=1 and site.Sitename like 'lakshmisite' ", use:

' where GSUStatus.GSUStatusID=1 and site.Sitename like ''lakshmisite'''

Notice that I am using two apostrophes per each one inside the string.

As you can see, you are setting QUOTED_IDENTIFIER to on, when creating the sp, so anything enclosed by double quote will be interprete as an identifier (name of a column, table, etc.), so when you pass that value to the sp, it will look like

...

SystemType.SystemTypeID=Site.SystemTypeID INNER JOIN GSUStatus ON Site.GSUStatusID=GSUStatus.GSUStatusID +

" where GSUStatus.GSUStatusID=1 and site.Sitename like 'lakshmisite' "

and there is not such identifier in your db.

you can set QUOTED_IDENTIFIER to OFF, but I prefer to leave it as ON and use the other method to escape apostrophes.

AMB

|||

If you call it from any UI, the single quote will be automatically taken care by the providers/ADO classes. (since it is a parameter)

But when you test the sp, you have to use either escape sequence or as AMB sujest use the QUOTED_IDENTIFER OFF config.

|||

Thanks Mani :-)

Now it is working.

There were two problems. One

1)setQUOTED_IDENTIFIERON should be OFF

2)exec@.sqlstr should be exec(@.sqlstr)

Kusuma

|||

Hai Dalej,

Sorry for posting two times.

I need dynamic query for a searching -sitenames,Businessunit etc......... ( searching based on columns in a table)

Now the problem is solved by giving exec(@.sqlstr) instead of exec @.sqlstr.

Thanks for your help :-)

Kusuma

Monday, March 26, 2012

Normal Procedure for shutdown SQL Server

Dear Sir,
I have a cluster Active/Passive cluster setting, Win2003. I would like to
know the normal procedures for shuting down the SQL Server on both nodes. Is
that needed to disable the passive node before using SQL Manager to shutdown
SQL Server?Please kindly advise!
Many thanks!
From,
Henry
Hi
Do not use SQL Manager to do anything with clustered SQL servers.
You must use Cluster Administrator to take a group offline or bring it
online again.
If you use SQL Manager, you in effect cause a failover.
Regards
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Henry" wrote:

> Dear Sir,
> I have a cluster Active/Passive cluster setting, Win2003. I would like to
> know the normal procedures for shuting down the SQL Server on both nodes. Is
> that needed to disable the passive node before using SQL Manager to shutdown
> SQL Server?Please kindly advise!
> Many thanks!
> From,
> Henry
>
sql

NOP in sysprocesses (cmd column)

Can somebody please tell me what 'NOP' is in the cmd column of sysprocesses
(SQL2K) noticed this when a stored procedure was running . .. I could not
find anything about this cmd (relating to SQL) on the internet . . .however
there were some references to NOP in c# and .NET programming
Thanks for your help
Olu Adedeji
Baysignia Systems
In other areas NOP means "No Operation", but I do not know if that is true
here..
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Olu Adedeji" <OluAdedeji@.discussions.microsoft.com> wrote in message
news:ACD1A5E9-503C-41D7-9F6D-9C8D2ABA7EFD@.microsoft.com...
> Can somebody please tell me what 'NOP' is in the cmd column of
sysprocesses
> (SQL2K) noticed this when a stored procedure was running . .. I could not
> find anything about this cmd (relating to SQL) on the internet . .
..however
> there were some references to NOP in c# and .NET programming
> Thanks for your help
>
> Olu Adedeji
> Baysignia Systems
|||Thanks Wayne
"Wayne Snyder" wrote:

> In other areas NOP means "No Operation", but I do not know if that is true
> here..
> --
> Wayne Snyder, MCDBA, SQL Server MVP
> Mariner, Charlotte, NC
> www.mariner-usa.com
> (Please respond only to the newsgroups.)
> I support the Professional Association of SQL Server (PASS) and it's
> community of SQL Server professionals.
> www.sqlpass.org
> "Olu Adedeji" <OluAdedeji@.discussions.microsoft.com> wrote in message
> news:ACD1A5E9-503C-41D7-9F6D-9C8D2ABA7EFD@.microsoft.com...
> sysprocesses
> ..however
>
>

NOP in sysprocesses (cmd column)

Can somebody please tell me what 'NOP' is in the cmd column of sysprocesses
(SQL2K) noticed this when a stored procedure was running . .. I could not
find anything about this cmd (relating to SQL) on the internet . . .however
there were some references to NOP in c# and .NET programming
Thanks for your help
Olu Adedeji
Baysignia SystemsIn other areas NOP means "No Operation", but I do not know if that is true
here..
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Olu Adedeji" <OluAdedeji@.discussions.microsoft.com> wrote in message
news:ACD1A5E9-503C-41D7-9F6D-9C8D2ABA7EFD@.microsoft.com...
> Can somebody please tell me what 'NOP' is in the cmd column of
sysprocesses
> (SQL2K) noticed this when a stored procedure was running . .. I could not
> find anything about this cmd (relating to SQL) on the internet . .
.however
> there were some references to NOP in c# and .NET programming
> Thanks for your help
>
> Olu Adedeji
> Baysignia Systems|||Thanks Wayne
"Wayne Snyder" wrote:

> In other areas NOP means "No Operation", but I do not know if that is true
> here..
> --
> Wayne Snyder, MCDBA, SQL Server MVP
> Mariner, Charlotte, NC
> www.mariner-usa.com
> (Please respond only to the newsgroups.)
> I support the Professional Association of SQL Server (PASS) and it's
> community of SQL Server professionals.
> www.sqlpass.org
> "Olu Adedeji" <OluAdedeji@.discussions.microsoft.com> wrote in message
> news:ACD1A5E9-503C-41D7-9F6D-9C8D2ABA7EFD@.microsoft.com...
> sysprocesses
> ..however
>
>

NOP in sysprocesses (cmd column)

Can somebody please tell me what 'NOP' is in the cmd column of sysprocesses
(SQL2K) noticed this when a stored procedure was running . .. I could not
find anything about this cmd (relating to SQL) on the internet . . .however
there were some references to NOP in c# and .NET programming
Thanks for your help
Olu Adedeji
Baysignia SystemsIn other areas NOP means "No Operation", but I do not know if that is true
here..
--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Olu Adedeji" <OluAdedeji@.discussions.microsoft.com> wrote in message
news:ACD1A5E9-503C-41D7-9F6D-9C8D2ABA7EFD@.microsoft.com...
> Can somebody please tell me what 'NOP' is in the cmd column of
sysprocesses
> (SQL2K) noticed this when a stored procedure was running . .. I could not
> find anything about this cmd (relating to SQL) on the internet . .
.however
> there were some references to NOP in c# and .NET programming
> Thanks for your help
>
> Olu Adedeji
> Baysignia Systems|||Thanks Wayne
"Wayne Snyder" wrote:
> In other areas NOP means "No Operation", but I do not know if that is true
> here..
> --
> Wayne Snyder, MCDBA, SQL Server MVP
> Mariner, Charlotte, NC
> www.mariner-usa.com
> (Please respond only to the newsgroups.)
> I support the Professional Association of SQL Server (PASS) and it's
> community of SQL Server professionals.
> www.sqlpass.org
> "Olu Adedeji" <OluAdedeji@.discussions.microsoft.com> wrote in message
> news:ACD1A5E9-503C-41D7-9F6D-9C8D2ABA7EFD@.microsoft.com...
> > Can somebody please tell me what 'NOP' is in the cmd column of
> sysprocesses
> > (SQL2K) noticed this when a stored procedure was running . .. I could not
> > find anything about this cmd (relating to SQL) on the internet . .
> ..however
> > there were some references to NOP in c# and .NET programming
> >
> > Thanks for your help
> >
> >
> > Olu Adedeji
> > Baysignia Systems
>
>sql

Friday, March 23, 2012

Noob need help with recursion

I created a table called MyTable with the following fields :

Id int
Name char(200)
Parent int

I also created the following stored procedure named Test, which is supposed to list all records and sub-records.

CREATE PROCEDURE Test
@.Id int
AS

DECLARE @.Name char(200)
DECLARE @.Parent int

DECLARE curLevel CURSOR LOCAL FOR
SELECT * FROM MyTable WHERE Parent = @.Id
OPEN curLevel
FETCH NEXT FROM curLevel INTO @.Id, @.Name, @.Parent
WHILE @.@.FETCH_STATUS = 0
BEGIN
SELECT @.Id AS Id, @.Name AS Name, @.Parent AS Parent
EXEC Test @.Id
FETCH NEXT FROM curLevel INTO @.Id, @.Name, @.Parent
END

CLOSE curLevel
DEALLOCATE curLevel
GO

I added a MxDataGrid and DataSourceControl.
SelectCommand property of the DataSourceControl = EXEC Test 0

When I run the aspx page, it only shows 1 record. I tried to change the parameter to 1, 2, 3 but it always shows only 1 record (not the same tho).

Is there something wrong with the stored procedure ?Ok, I made some modifications to make it work properly but there is some limitations. I have to store the results in a temp table. Can I do something similar but without the temp table ?

(Note : I changed some field/table names)


-- ----------------------
-- Fill and select the temp table where the nodes and sub nodes id are stored
-- ----------------------
CREATE PROCEDURE GetNodesAndSubNodes
@.NodeId INT
AS

DELETE FROM TmpNodesAndSubNodes
EXEC GetNodesAndSubNodesRecursive @.NodeId
SELECT * FROM TmpNodesAndSubNodes
GO

-- ----------------------
-- Fill the temp table with the id's of the nodes and it's sub nodes
-- ----------------------
CREATE PROCEDURE GetNodesAndSubNodesRecursive
@.NodeId INT
AS

-- Store the node id into the temp table
INSERT INTO TmpNodesAndSubNodes VALUES(@.NodeId)

-- Declare a local cursor to seek in the nodes table
-- and some variables to retreive the values
DECLARE @.CurrentNodeId INT
DECLARE @.CurrentParentNodeId INT
DECLARE curLevel CURSOR LOCAL FOR
SELECT Id FROM Nodes WHERE ParentNodeId=@.NodeId

-- Fetchs the records and call the recursive method for each node id
OPEN curLevel
FETCH NEXT FROM curLevel INTO @.CurrentNodeId
WHILE @.@.FETCH_STATUS = 0
BEGIN
EXEC GetNodesAndSubNodesRecursive @.CurrentNodeId
FETCH NEXT FROM curLevel INTO @.CurrentNodeId
END

-- Clean up
CLOSE curLevel
DEALLOCATE curLevel

GO

|||Aaarg :)

I decided to work on a non recursive solution.

Noob count question

I have a table of events, which stores an event ID, event Name and event
date.
I want to write a stored procedure that returns the next 4 events starting
from today, so far I have:
SELECT
[EventID],
[EventName],
[EventDate]
FROM
Events
WHERE
(DATEDIFF(dd, GETDATE(), EventDate) > 0)
ORDER BY
[EventDate] ASC
How do I add a clause to say only return a maximum of 4 (or however many is
left if fewer) events from today?Use the TOP clause using 4 as the number of records to be returned.
Optionally SET ROWCOUNT. But TOP is preferred.
HTH
Jerry
"Seefor" <invalid@.email.address> wrote in message
news:DfBXe.111419$G8.92946@.text.news.blueyonder.co.uk...
>I have a table of events, which stores an event ID, event Name and event
>date.
> I want to write a stored procedure that returns the next 4 events starting
> from today, so far I have:
> SELECT
> [EventID],
> [EventName],
> [EventDate]
> FROM
> Events
> WHERE
> (DATEDIFF(dd, GETDATE(), EventDate) > 0)
> ORDER BY
> [EventDate] ASC
>
> How do I add a clause to say only return a maximum of 4 (or however many
> is left if fewer) events from today?
>|||many thanks
"Jerry Spivey" <jspivey@.vestas-awt.com> wrote in message
news:etg0fRTvFHA.1392@.tk2msftngp13.phx.gbl...
> Use the TOP clause using 4 as the number of records to be returned.
> Optionally SET ROWCOUNT. But TOP is preferred.
> HTH
> Jerry
> "Seefor" <invalid@.email.address> wrote in message
> news:DfBXe.111419$G8.92946@.text.news.blueyonder.co.uk...
>|||If you want to use an index on EventDate efficiently, make sure you don't
have any manipulation on the filtered column.
Instead of:
WHERE (DATEDIFF(dd, GETDATE(), EventDate) > 0)
Use:
WHERE EventDate >= CONVERT(VARCHAR(8), GETDATE(), 112)
Specify TOP 4 in the SELECT list, and sort by EventDate .
BG, SQL Server MVP
www.SolidQualityLearning.com
"Seefor" <invalid@.email.address> wrote in message
news:DfBXe.111419$G8.92946@.text.news.blueyonder.co.uk...
>I have a table of events, which stores an event ID, event Name and event
>date.
> I want to write a stored procedure that returns the next 4 events starting
> from today, so far I have:
> SELECT
> [EventID],
> [EventName],
> [EventDate]
> FROM
> Events
> WHERE
> (DATEDIFF(dd, GETDATE(), EventDate) > 0)
> ORDER BY
> [EventDate] ASC
>
> How do I add a clause to say only return a maximum of 4 (or however many
> is left if fewer) events from today?
>

Tuesday, March 20, 2012

Non-English Characters in Table/Stored Procedure Names

Could you tell me what are the limitations/concerns regarding Non-English characters being used for Table/Views/Stored Procedure Names?

I have been studying that very topic, my web site is built on 12 languages at present, and storing documents with UTF-8 encoding in SQL text fields works well. Its a bit tricky though with HTML tags embedded.|||

See the topic below for more details:

http://msdn2.microsoft.com/en-us/library/ms175874(SQL.90).aspx

|||Thanks!

Monday, March 12, 2012

Non Usesfull error Message

ERROR MSG:

Msg 515, Level 16, State 2, Server SQL\CIS, Procedure ssp_gas_CustomerCancellation_A, Line 161

Cannot insert the value NULL into column '', table ''; column does not allow nulls. INSERT fails.

The statement has been terminated.

Why didn't it actually tell me the Column and table name? i've never seen this before?

Anyone can help

Thanks

Marios

Oh I know this isn't the right forum but i couldn't find the right one to post in.

How is the procedure executed?

Not sure about why the error message is like that. Are there many fields in the table that do not allow nulls, I'd start checking those.

|||

It is called from another Stored Procedure the Stored Procedure that it rasises the error in is about 600lines of code and there are serval places where it Inserts int Tables and Temp Tables. I've looked at the data passed and which fields they are passed in to but i don't see where this error happends. It has only happend in our Production Database i can not so far reproduce it in our development environment. I don't understand why it doesn't show me the column and table

Thanks

Marios

|||

Do you explicity create your temporary tables or create/populate them through select into statments? Maybe that is why it doesn't show the table/column name (the fact that that it is a temporary table).

Nevermind, just tested that and it doesn't seem to be the case.

|||

no i explicitly defne the tables for temp tables before using them and but they are declare

CREATE #TableName

(

)

|||The only other thing I can think of, and I realize it may be impractical due to the large amount of code within the stored procedure is to use try...catch statements.|||i can't because it's a SQL 2000 server

Wednesday, March 7, 2012

nocount on problem

i use
set nocount on inside the stored procedure at the beginning however the
Number of Rows Counted/Affected shows up when I execute the stored
procedure in query analyzer using execute sprocName. I also tried to
add the

SET NOCOUNT ON at the beginning of the procedure and it still shows the
number of rows affected.
if i set

set nocount on
exec sprocName then the result set does not show the number of rows
affected.

Any idea why this happens? I know that NOCOUNT is set on runtime not
parse time.

Thanks!"GM" <gentian.metaj@.trustasc.com> wrote in message
news:1104772581.850237.15630@.z14g2000cwz.googlegro ups.com...
>i use
> set nocount on inside the stored procedure at the beginning however the
> Number of Rows Counted/Affected shows up when I execute the stored
> procedure in query analyzer using execute sprocName. I also tried to
> add the
> SET NOCOUNT ON at the beginning of the procedure and it still shows the
> number of rows affected.
> if i set
> set nocount on
> exec sprocName then the result set does not show the number of rows
> affected.
> Any idea why this happens? I know that NOCOUNT is set on runtime not
> parse time.
> Thanks!

I have no idea - the following trivial example works for me, ie. it does not
display the rows affected (in Query Analyzer), using MSSQL 2000 build
8.00.760:

create proc foo
as
begin
set nocount on
select * from master.dbo.sysdatabases
end
go

exec foo
go

If this doesn't help, you might want to post a minimal code example for
Query Analyzer which shows the problem you have, along with details of your
MSSQL version.

Simon|||Thanks Simon. NoCount seems to work OK. The issue was that i was using
IMCEDA SpeedSQL and i'm assuming somehow they do something weird
(Probably get @.@.rowCount or something) but when i ran it on regular QA
it seemed to work. Apparently Imceda SpeedSQL (Formerly known and
SQLExpress) must put some extra code under their interface.

While i was reading Books online it says "The setting of SET NOCOUNT is
set at execute or run time and not at parse time." What are the
implications of that statement?

Thanks

Gent|||"GM" <gentian.metaj@.trustasc.com> wrote in message
news:1104779732.275600.51970@.c13g2000cwb.googlegro ups.com...
> Thanks Simon. NoCount seems to work OK. The issue was that i was using
> IMCEDA SpeedSQL and i'm assuming somehow they do something weird
> (Probably get @.@.rowCount or something) but when i ran it on regular QA
> it seemed to work. Apparently Imceda SpeedSQL (Formerly known and
> SQLExpress) must put some extra code under their interface.
> While i was reading Books online it says "The setting of SET NOCOUNT is
> set at execute or run time and not at parse time." What are the
> implications of that statement?
> Thanks
> Gent

As I understand it, a parse-time option is set when the code is parsed, so
it will be set even if the branch of code it's in is never executed (because
of branching logic or error handling). A run-time option is set only when
that part of code really does execute. See "SET Options" in Books Online for
more details.

By the way, if you want to check up on exactly what SpeedSQL is doing, you
can use Profiler to trace all TSQL sent from it to the server.

Simon