Quantcast
Channel: Microsoft Dynamics AX Forum - Recent Threads
Viewing all articles
Browse latest Browse all 175888

RE: Invalid character in ascii string

$
0
0

If you know what characters you are searching for:

CREATE TABLE ##TempTables  

   (  

   ROWID BIGINT NOT NULL IDENTITY(1,1) PRIMARY KEY  

   ,[TableName] VARCHAR(MAX)  

   ,[ColName] VARCHAR(MAX)  

   ,[Found] int  

   )  

DECLARE @Loop INT  

DECLARE @LoopMAX INT  

DECLARE @SQL VARCHAR(max)  

DECLARE @Value VARCHAR(max)  

DECLARE @ValueNew VARCHAR(max)  

DECLARE @ColName VARCHAR(max)  

DECLARE @tblName VARCHAR(max)  

--***************************************  

--TYPE IN THE VALUE YOU LOOKING FOR BELOW  

--***************************************  

SELECT @Value = 'Raiders'  

--***************************************

--INSERT ALL TABLE NAMES AND COLUMS HERE  

INSERT INTO ##TempTables  

   (  

   [TableName]  

   ,[ColName]  

   ,[Found]  

   )  

SELECT  

   [T].[Name] as [TableName]  

   ,[C].[Name] as [ColName]  

   , 0 as [found]  

FROM sys.tables [T]  

   INNER JOIN sys.Columns [C]  

   ON [C].[Object_ID] = [T].[Object_ID]  

SELECT    

   @Loop = 1  

   ,@LoopMAX = MAX(ROWID)  

FROM ##TempTables  

WHILE (@Loop <= @LoopMAX)  

BEGIN  

   SELECT  

      @ColName = [ColName]  

      ,@tblName = [TableName]  

   FROM ##TempTables  

   WHERE ROWID = @Loop  

   SELECT @SQL =  

'IF EXISTS(SELECT ' + @ColName + ' FROM ' + @tblName + ' WHERE CAST(' + @ColName + ' as VARCHAR(max))= ''' + @Value + ''')  

BEGIN  

   UPDATE ##TempTables SET FOUND = 1 Where ROWID = '+ cast(@Loop as varchar(max)) +'  

END'  

      EXEC (@SQL)  

   SET @Loop = @Loop + 1  

END  

SELECT  

*

   FROM ##TempTables  

   WHERE Found = 1  

DROP TABLE ##TempTables  


Viewing all articles
Browse latest Browse all 175888

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>