Skip to main content

Notifications

Announcements

No record found.

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.
  • André Arnaud de Calavon Profile Picture
    292,886 Super User 2025 Season 1 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?
  • 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
    292,886 Super User 2025 Season 1 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? 

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,886 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,766 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans