web
You’re offline. This is a read only version of the page.
close
Skip to main content
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
    299,956 Super User 2025 Season 2 on at
    Error converting varchar to Bigint TSQL
    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
    Error converting varchar to Bigint TSQL
    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
    299,956 Super User 2025 Season 2 on at
    Error converting varchar to Bigint TSQL
    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

Responsible AI policies

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

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 684 Super User 2025 Season 2

#2
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 588

#3
Martin Dráb Profile Picture

Martin Dráb 542 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans