Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL - Error in creating stored procedure

Posted on 2012-03-18
3
Medium Priority
?
508 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 1600 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 400 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
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 UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

610 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