web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Invalid character in ascii string

(0) ShareShare
ReportReport
Posted on by

in search of  sql code to id (within a table) the culprit of 'invalid character in ascii string' error  

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    237,987 Most Valuable Professional on at

    Please give us more information about what you're doing, where you get the error, what's the SQL query and so on.

  • Community Member Profile Picture
    on at

    there is an ax batch job producing the invalid character error; attempting to query (using SQL)  certain columns in the tables involved to id the invalid characters.

  • Community Member Profile Picture
    on at

    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  

  • Community Member Profile Picture
    on at

    thanks for response

  • Community Member Profile Picture
    on at

    I don't know up front what character I'm looking for;  got around issue another way.  Thanks for your time

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans