Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Analysis Server and Reporting Services (2005)
 Problem with temp table meta data

Author  Topic 

icw
Constraint Violating Yak Guru

378 Posts

Posted - 2009-01-03 : 02:11:39
Hi, Someone has given me a great stored proc that searches all rows of ALL tables for a string (provided by a parameter). I am trying to get the thing to run from a SQL report.
The problem I am having is that the SP creates a Temp table and the report doesn't like it.
I create my datasource and change the query to Stored Procedure and typed in the name of the SP then ran the query provided a searchvalue and my results appeared in the DATA tab, then went over to the layout tab and get an error saying "cannot generate a list of fields for the query"..."Invalid object name '#Results' "
I will also provide the text for the SP below.


set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER PROC [dbo].[SearchAllTables]
(
@SearchStr nvarchar(100)
)
AS
BEGIN



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 ColumnName, ColumnValue FROM #Results
END





Thanks in advance if you can help

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-03 : 07:05:24
its a known problem. though an error comes saying invalid object name, it still works fine. just refresh the dataset and you will get all fields populated automatically in layout tab which you can drag and drop in layout tab.
Go to Top of Page

icw
Constraint Violating Yak Guru

378 Posts

Posted - 2009-01-05 : 09:50:17
thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-05 : 10:00:49
welcome
let me know how you got on
Go to Top of Page

icw
Constraint Violating Yak Guru

378 Posts

Posted - 2009-01-08 : 06:04:55
it's fine now and working ..thanks a lot
Go to Top of Page
   

- Advertisement -