Unix Technical Forum

stored procedure update HUGE PROBLEM

This is a discussion on stored procedure update HUGE PROBLEM within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi, I need help on this one. For the past two days, whenever I make a modification to a ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 02:52 PM
Patrik
 
Posts: n/a
Default stored procedure update HUGE PROBLEM

Hi,

I need help on this one. For the past two days, whenever I make a
modification to a stored procedure using enterprise manager (Apply),
the stored procedure stops working.

If I copy it under a new name, it works but as soon as I make a
modification, it stops working. I am going crazy on this one.

The error : wrong column name. He doesn't recognize the column name on
a very straighforward line : SELECT @SQL1 = 'SELECT @Total1 = Count(*)
FROM dbo.Tbl_Report WHERE Utilisateur = "'+@utilisateur+'"

For example 'sa' is not a column (it skips Utilisateur as the column
name).

Very strange. Never had this problem in the past. thank you very much.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 02:52 PM
Jens
 
Posts: n/a
Default Re: stored procedure update HUGE PROBLEM

Donīt know which "as" you mean but I would assume to write the
character rather than doublequoting them, that more readable.

SELECT @SQL1 = 'SELECT @Total1 = Count(*) FROM dbo.Tbl_Report WHERE
Utilisateur =' +CHAR(39) +@utilisateur +CHAR(39)

HTH, Jens Suessmeyer.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 02:52 PM
David Portas
 
Posts: n/a
Default Re: stored procedure update HUGE PROBLEM

Don't ever create or alter procs in Enterprise Manager. Use Query
Analyzer and specify SET QUOTED_IDENTIFIER and ANS_NULLS ON or OFF as
required. Prefereably always ON.

Your code fragment looks wrong anyway. Presumably it should be:

SELECT @SQL1 = 'SELECT @Total1 = Count(*) FROM dbo.Tbl_Report WHERE
Utilisateur = '''+@utilisateur+''''

Don't use double quotes for string delimiters.

--
David Portas
SQL Server MVP
--

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-29-2008, 02:52 PM
Erland Sommarskog
 
Posts: n/a
Default Re: stored procedure update HUGE PROBLEM

Patrik (patrik.maheux@umontreal.ca) writes:
> I need help on this one. For the past two days, whenever I make a
> modification to a stored procedure using enterprise manager (Apply),
> the stored procedure stops working.
>
> If I copy it under a new name, it works but as soon as I make a
> modification, it stops working. I am going crazy on this one.
>
> The error : wrong column name. He doesn't recognize the column name on
> a very straighforward line : SELECT @SQL1 = 'SELECT @Total1 = Count(*)
> FROM dbo.Tbl_Report WHERE Utilisateur = "'+@utilisateur+'"
>
> For example 'sa' is not a column (it skips Utilisateur as the column
> name).
>
> Very strange. Never had this problem in the past. thank you very much.


The problem is that " sometimes is a string delimiter in T-SQL and
sometimes it is an identifier delimiter. This depends on the setting
QUOTED_IDENTIFIER. This setting is ON by default in most environment,
and this is also the recommended setting since some functionality
requires this setting to be in effect. It happens to be the case that
EM has this setting off by default, but EM is really a crappy tool for
maintaing stored procedures. Use Query Analyzer instead.

I appreciate that when working with dynamic SQL, it's very nice to
have access to both ' and " as string delimiters. You can put
SET QUOTED_IDENTIFIER OFF first in you dynamic SQL, and then you can
use " within the dynamic SQL. But that presumes that you are not using
indexed views, so best is probably to stick with ' only - even if
the list of ' can sometimes become unbelievably long.

By the way, there is no need for dynamic SQL in the snippet you posted.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-29-2008, 02:52 PM
Patrik
 
Posts: n/a
Default Re: stored procedure update HUGE PROBLEM

Thank you both for these clarifications. I will indeed stop using EM
and will read furthermor on quoted_identifier as I leave it on.

Erland Sommarskog wrote:
> Patrik (patrik.maheux@umontreal.ca) writes:
> > I need help on this one. For the past two days, whenever I make a
> > modification to a stored procedure using enterprise manager (Apply),
> > the stored procedure stops working.
> >
> > If I copy it under a new name, it works but as soon as I make a
> > modification, it stops working. I am going crazy on this one.
> >
> > The error : wrong column name. He doesn't recognize the column name on
> > a very straighforward line : SELECT @SQL1 = 'SELECT @Total1 = Count(*)
> > FROM dbo.Tbl_Report WHERE Utilisateur = "'+@utilisateur+'"
> >
> > For example 'sa' is not a column (it skips Utilisateur as the column
> > name).
> >
> > Very strange. Never had this problem in the past. thank you very much.

>
> The problem is that " sometimes is a string delimiter in T-SQL and
> sometimes it is an identifier delimiter. This depends on the setting
> QUOTED_IDENTIFIER. This setting is ON by default in most environment,
> and this is also the recommended setting since some functionality
> requires this setting to be in effect. It happens to be the case that
> EM has this setting off by default, but EM is really a crappy tool for
> maintaing stored procedures. Use Query Analyzer instead.
>
> I appreciate that when working with dynamic SQL, it's very nice to
> have access to both ' and " as string delimiters. You can put
> SET QUOTED_IDENTIFIER OFF first in you dynamic SQL, and then you can
> use " within the dynamic SQL. But that presumes that you are not using
> indexed views, so best is probably to stick with ' only - even if
> the list of ' can sometimes become unbelievably long.
>
> By the way, there is no need for dynamic SQL in the snippet you posted.
>
>
> --
> Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
>
> Books Online for SQL Server SP3 at
> http://www.microsoft.com/sql/techinf...2000/books.asp


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:32 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com