title: How to convert numeric to nvarchar in SQL Server?
body: <p>Consider the following table. I use a trigger to add to the table. In the column of converting the number to the string, it fails.</p>
  
  <pre><code>CREATE TABLE [dbo].[tblAIAgent]
  (
      [AgentCode] [NVARCHAR](10) NOT NULL,
      [NationalCode] [BIGINT] NOT NULL 
           CONSTRAINT [DF_tblAIAgent_NationalCode]  DEFAULT ((0)),
      [FirstName] [NVARCHAR](50) NOT NULL 
           CONSTRAINT [DF_tblAIAgent_Name] DEFAULT (''),
      [LastName] [NVARCHAR](50) NOT NULL 
           CONSTRAINT [DF_tblAIAgent_Family] DEFAULT (''),
      [IsActive] [BIT] NOT NULL 
           CONSTRAINT [DF_tblAIAgent_Active] DEFAULT ((1)),
      [Counter] [INT] IDENTITY(1,1) NOT NULL,
  
      CONSTRAINT [PK_tblAIAgent] 
          PRIMARY KEY CLUSTERED 
  )
  
  ALTER TRIGGER [dbo].[AgentInsert] 
  ON [dbo].[tblAIAgent]
  INSTEAD OF INSERT
  AS
  BEGIN
      DECLARE @AgentCode NVARCHAR(10)
      DECLARE @NationalCode BIGINT
      DECLARE @FirstName NVARCHAR(50)
      DECLARE @LastName NVARCHAR(50)
      DECLARE @IsActive BIT
      DECLARE @CounterIs INT
  
      SET @CounterIs = @@IDENTITY
  
      SELECT
          @AgentCode = AgentCode,
          @NationalCode = NationalCode,
          @FirstName = FirstName,
          @LastName = LastName,
          @IsActive = IsActive 
      FROM inserted
  
      INSERT INTO tblAIAgent (NationalCode, FirstName, LastName, IsActive, AgentCode)
      VALUES (@NationalCode, @FirstName, @LastName, @IsActive, 'Agent_' + CAST(@CounterIs AS NVARCHAR(4))) 
  END
  </code></pre>