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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Error converting varchar to Bigint TSQL

(1) ShareShare
ReportReport
Posted on by 2,366
Hi Folks,
 
Can you please fix below query to work, I keep getting error converting data type varchar to big int when trying to run via runclass/Job.
declare @dbo varchar(50) set @dbo = 'Dbo.seq_' declare @tableID varchar(10) set @tableID = 'SOMETABLEID' declare @sql varchar(500) set @sql = 'alter sequence' +@dbo+@tableID + 'minvalue' +CAST(YOURRECIDValue as bigint) +'restart with'  +CAST(YOURRECIDValue as bigint) exec (@sql)
 
 
Thanks
Mav.
I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    303,730 Super User 2026 Season 1 on at
    Hi Mav,
     
    Can you explain if you have X++ coding that generates this SQL command? What is this SQL about? Where exactly do you get the error? 
  • Community member Profile Picture
    2,366 on at
    Hi Andre,
     
    Yes I have the X++ code which generates the statement. All other statements with same x++ code works just fine.
    It is only this code which gives the error and even when I run the code directly in sql I get same error . 
    Error in SQL 
    Shared in previous post 

    SQL query
    Shared in previous port

    X++ code
    Shared below.




    Error in X++ 
    [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Error converting data type varchar to bigint.




     public static int64  alterRecId(TableId _tableId, int64 _maxRecId)
        {
            //Run SQL to alter seq id
            //alter sequence dbo.seq_7051 minvalue alterRecId restart with alterRecId
            int64 alterRecId = _maxRecId+1;
            const str sqlStatementText = "declare @dbo varchar(50) set @dbo = 'Dbo.seq_' declare @tableID varchar(10)  set @tableID = @SelectedTableId declare @sql varchar(500) set @sql = 'alter sequence ' +@dbo+@tableID + 'minvalue ' + @AlterRecId + 'restart with'  + @AlterRecId exec (@sql)";
            var connection = new Connection();
            Statement statement = connection.createStatement();
            Map paramMap = SqlParams::create();
            paramMap.add('SelectedTableId', _tableId);
            paramMap.add('AlterRecId', alterRecId);
            var results= statement.executeQueryWithParameters(sqlStatementText, paramMap);
            results.next();
            str result1 = results.getString(1);
            alterRecId = str2Int64(result1);
            statement.close();
            return alterRecId;
        }
    Thanks
    Mav
  • André Arnaud de Calavon Profile Picture
    303,730 Super User 2026 Season 1 on at
    Hi Mav,
     
    What exact business issue are you trying to solve? What should be the result of the query? Do you want to read data or write data to a table?

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 663

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 439 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 337 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans