Cut column text in SQL Server

0

I have a column of a table located on a Linked Server (from Oracle) that exceeds the varchar (Max) of a column in a SQl Server table. I need to cut the values to the Max of the column in order to pass the data through a SQL Server Job. This is the query I have in the step of Job:

TRUNCATE TABLE SMARTCLOUD.DBO.COMMLOG

INSERT INTO SMARTCLOUD.DBO.COMMLOG

SELECT [COMMLOGID]
      ,[SENDTO]
      ,[SENDFROM]
      ,[SUBJECT]
      ,[CREATEBY]
      ,[CREATEDATE]
      ,[COMMLOGUID]
      ,[MESSAGE]
  FROM [SMARTCLOUD]..[MAXIMO].[COMMLOG]

The column that exceeds the maximum is [MESSAGE]

    
asked by Alonso Fallas 20.10.2016 в 22:23
source

1 answer

2

You can use the LEFT function of MSSQL

TRUNCATE TABLE SMARTCLOUD.DBO.COMMLOG

INSERT INTO SMARTCLOUD.DBO.COMMLOG

SELECT [COMMLOGID]
      ,[SENDTO]
      ,[SENDFROM]
      ,[SUBJECT]
      ,[CREATEBY]
      ,[CREATEDATE]
      ,[COMMLOGUID]
      ,LEFT([MESSAGE],X) as MESSAGE/*donde X es el tamaño de tu campo*/

FROM [SMARTCLOUD]..[MAXIMO].[COMMLOG]
    
answered by 20.10.2016 / 22:29
source