Solved

SQL - Error in creating stored procedure

Posted on 2012-03-18
3
500 Views
Last Modified: 2012-03-19
I have an error of
Msg 262, Level 14, State 1, Procedure SearchAllTablesForSimilarValue, Line 65
CREATE PROCEDURE permission denied in database 'Database1'.

I sign on as 'sa'.  Not sure why the error occur. How do I find out why?  

USE [Database1]
GO
/****** Object:  StoredProcedure [dbo].[SearchAllTablesForSimilarValue]    
Script Date: 01/03/2012 22:27:38 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROC [dbo].[SearchAllTablesForSimilarValue]
(
      @SearchStr nvarchar(100)
)
AS
BEGIN

      -- Copyright © 2002 Narayana Vyas Kondreddi. All rights reserved.
      -- Purpose: To search all columns of all tables for a given search string
      -- Written by: Narayana Vyas Kondreddi
      -- Site: http://vyaskn.tripod.com
      -- Tested on: SQL Server 7.0 and SQL Server 2000
      -- Date modified: 28th July 2002 22:50 GMT


      CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue nvarchar(3630))

      SET NOCOUNT ON

      DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110)
      SET  @TableName = ''
      SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')

      WHILE @TableName IS NOT NULL
      BEGIN
            SET @ColumnName = ''
            SET @TableName =
            (
                  SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))
                  FROM       INFORMATION_SCHEMA.TABLES
                  WHERE             TABLE_TYPE = 'BASE TABLE'
                        AND      QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) > @TableName
                        AND      OBJECTPROPERTY(
                                    OBJECT_ID(
                                          QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)
                                           ), 'IsMSShipped'
                                           ) = 0
            )

            WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)
            BEGIN
                  SET @ColumnName =
                  (
                        SELECT MIN(QUOTENAME(COLUMN_NAME))
                        FROM       INFORMATION_SCHEMA.COLUMNS
                        WHERE             TABLE_SCHEMA      = PARSENAME(@TableName, 2)
                              AND      TABLE_NAME      = PARSENAME(@TableName, 1)
                              AND      DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar')
                              AND      QUOTENAME(COLUMN_NAME) > @ColumnName
                  )
      
                  IF @ColumnName IS NOT NULL
                  BEGIN
                        INSERT INTO #Results
                        EXEC
                        (
                              'SELECT ''' + @TableName + '.' + @ColumnName + ''', LEFT(' + @ColumnName + ', 3630)
                              FROM ' + @TableName + ' (NOLOCK) ' +
                              ' WHERE ' + @ColumnName + ' Like ' + @SearchStr2
                        )
                  END
            END      
      END

      SELECT DISTINCT ColumnName, ColumnValue FROM #Results  -- <== Error point to this line
      ORDER BY ColumnName ASC
END
0
Comment
Question by:tommym121
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Accepted Solution

by:
micropc1 earned 400 total points
ID: 37736233
See if granting permissions to your account helps...

GRANT CREATE PROCEDURE to [sa]

Open in new window

0
 
LVL 9

Assisted Solution

by:sachinpatil10d
sachinpatil10d earned 100 total points
ID: 37736315
what micropc1 says is right

Msg 262, Level 14, State 1, Procedure SearchAllTablesForSimilarValue, Line 65
CREATE PROCEDURE permission denied in database 'Database1'.

error occurs generally when sa user does not have the permission to create procedure, function etc.

you will have to assign the create permission to user sa.

for Grant command check out the following link

http://msdn.microsoft.com/en-us/library/ms187965.aspx
0
 

Author Closing Comment

by:tommym121
ID: 37737128
Thanks
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question