Red Gate forums :: View topic - Unused Params & Variables
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
SQL Refactor 1
SQL Refactor 1 forum

Unused Params & Variables

Search in SQL Refactor 1 forum
Post new topic   Reply to topic
Jump to:  
Author Message
blackshirt



Joined: 26 Oct 2010
Posts: 2

PostPosted: Tue Oct 26, 2010 9:14 pm    Post subject: Unused Params & Variables Reply with quote

In SSMS I generated a script of all my SPs on the database. I then brought that script in and highlighted them all then selected SQL Refactor -> Find Unused Variables and Parameters........I get an error message saying it cant highlight some variables because of some syntax errors while being parsed. So then I started from beginning and highlighted SP1 and no issues. Then highlighted SP1 and SP2.....again no issues.....then I did SP1, SP2, and SP3 then got the error....so I just highlighted SP3 and again no issues.....so is there a limit, buffer limit, or something wrong with trying to do this against multiple SP's in your database?

My main goal is to try to run this utility against all my SP's in my DB and not just one by one which would take forever.

thanks
Back to top
View user's profile Send private message
Anu Deshpande



Joined: 20 Apr 2009
Posts: 595
Location: Cambridge

PostPosted: Thu Oct 28, 2010 3:12 pm    Post subject: Reply with quote

Many thanks for your post and apologies for inconvenience caused.

Are you able to parse the same multiple SP query through management Studio 'Parse' functionality?

As when I open multiple SP's in one Query Window and first parse it it gives me error: "Msg 154, Level 15, State 1, Procedure spArtikelBuchung, Line 240
a USE database statement is not allowed in a procedure, function or trigger."

But SQL Refactor do the job for me.

Kindly let me know the detailed version of SQL Refactor you have installed on your machine.

You can know the detailed version of SQL Refactor by navigating to SQL Refactor --> About SQL Refactor and version number is displayed on bottom right.
_________________
Anuradha Deshpande
Product Support
Redgate Software Ltd.
E-mail: support@red-gate.com
Back to top
View user's profile Send private message Send e-mail
blackshirt



Joined: 26 Oct 2010
Posts: 2

PostPosted: Thu Oct 28, 2010 3:30 pm    Post subject: Reply with quote

I am using SQL Refactor 1.5.1.83.......

When I hightlight the 3 SP's and press the "Parse" button it says "Command(s) completed successfully".......when I do that with "Find Unused variables and parameters".....I get the error in my original message.

Here is an example SP...........

CREATE PROCEDURE [Test].[procTest]
(
@Id uniqueidentifier
)
AS
BEGIN
SET NOCOUNT ON
DECLARE @Err int

SELECT [Id]
,[temId]
,[ActivityId]
,[AAmount]
FROM [test].[test1]
WHERE ([Id] = @Id)


IF @@Error = 0
BEGIN
IF @@RowCount = 0
BEGIN
RETURN 1
END
END

RETURN @@ERROR

END
GO
Back to top
View user's profile Send private message
Joojooflop



Joined: 01 Oct 2009
Posts: 5

PostPosted: Wed Nov 10, 2010 5:37 pm    Post subject: Reply with quote

I have the same issue. I still get the error if I strip down blackshirt's proc to this:
Code:
CREATE PROCEDURE procTest AS
  IF @@Error = 0 RETURN 1
  RETURN @@ERROR

Here's another very small proc that gives the same error:
Code:
CREATE PROCEDURE procTest AS
  DECLARE @Var1 INT
  SET @Var1 = 1
  SET @Var1 = 1

It seems to be something to do with the scan encountering the same variable a second time. For example, this is fine:
Code:
CREATE PROCEDURE [procTest] AS
  IF @@ERROR = 0 RETURN 1
  IF @@LANGID = 0 RETURN 1

...and this is fine:
Code:
CREATE PROCEDURE [procTest] AS
  IF @@LANGID = 0 RETURN 1
  IF @@ERROR = 0 RETURN 1

...but this gives the error:
Code:
CREATE PROCEDURE [procTest] AS
  IF @@LANGID= 0 RETURN 1
  IF @@LANGID= 0 RETURN 1

...and this gives the error:
Code:
CREATE PROCEDURE [procTest] AS
  IF @@ERROR = 0 RETURN 1
  IF @@ERROR = 0 RETURN 1

It's a great feature when it works. I hope it won't be too hard to fix it.
Back to top
View user's profile Send private message
mnowill



Joined: 28 Jan 2010
Posts: 4

PostPosted: Thu Apr 28, 2011 4:45 pm    Post subject: Me too... Reply with quote

I am having the same issue and can reproduce the the same situations as Joojooflop
Back to top
View user's profile Send private message
Joojooflop



Joined: 01 Oct 2009
Posts: 5

PostPosted: Thu Apr 28, 2011 6:42 pm    Post subject: Reply with quote

This appears to have been fixed in SQL Prompt 5.
Back to top
View user's profile Send private message
frisky



Joined: 02 Mar 2012
Posts: 2

PostPosted: Fri Mar 02, 2012 12:59 pm    Post subject: Re: Reply with quote

Joojooflop wrote:
This appears to have been fixed in SQL Prompt 5.

Haven't noticed any fixes. Still get the error in my original message when doing this with "Find Unused cell phone spy variables and parameters".
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group