Usage of WRITE function in SQL Server

Bandi
Posted by Bandi under Sql Server category on | Points: 40 | Views : 441
-- Replacing NULL value with temporary data.
use AdventureWorks2008R2
GO
SELECT DocumentSummary
FROM Production.Document
WHERE DocumentLevel = 1;
GO
UPDATE Production.Document
SET DocumentSummary = N'Replacing NULL value'
WHERE DocumentLevel = 1;
GO
SELECT DocumentSummary
FROM Production.Document
WHERE DocumentLevel = 1;
GO
-- Replacing temporary data with the correct data. Setting @Length to NULL
-- truncates all existing data from the @Offset position.
UPDATE Production.Document
SET DocumentSummary .WRITE(N'Carefully inspect and maintain the tires and crank arms.',0,NULL)
WHERE DocumentLevel = 1;
GO
SELECT DocumentSummary
FROM Production.Document
WHERE DocumentLevel = 1;
GO
-- Appending additional data to the end of the column by setting
-- @Offset to NULL.
UPDATE Production.Document
SET DocumentSummary .WRITE (N' Appending data to the end of the column.', NULL, 0)
WHERE DocumentLevel = 1;
GO
SELECT DocumentSummary
FROM Production.Document
WHERE DocumentLevel = 1;
GO
-- Removing all data from @Offset to the end of the existing value by
-- setting expression to NULL.
UPDATE Production.Document
SET DocumentSummary .WRITE (NULL, 58, 0)
WHERE DocumentLevel = 1;
GO
SELECT DocumentSummary
FROM Production.Document
WHERE DocumentLevel = 1;
GO
-- Removing partial data beginning at position 9 and ending at
-- position 21.
UPDATE Production.Document
SET DocumentSummary .WRITE ('',9, 12)
WHERE DocumentLevel = 1;
GO
SELECT DocumentSummary
FROM Production.Document
WHERE DocumentLevel = 1;
GO

Comments or Responses

Login to post response