Tutorial by Examples

The STUFF() function inserts a string into another string by first deleting a specified number of characters. The following example, deletes "Svr" and replaces it with "Server". This happens by specifying the start_position and length of the replacement. SELECT STUFF('SQL Svr D...
One common use for the FOR XML function is to concatenate the values of multiple rows. Here's an example using the Customers table: SELECT STUFF( (SELECT ';' + Email FROM Customers where (Email is not null and Email <> '') ORDER BY Email ASC FOR XM...
/* The result can be use for fast way to use columns on Insertion/Updates. Works with tables and views. Example: eTableColumns 'Customers' ColumnNames ------------------------------------------------------ Id, FName, LName, Email, PhoneNumber, PreferredContact INSERT INTO Customers (Id, ...
FOR XML PATH and STUFF to concatenate the multiple rows into a single row: select distinct t1.id, STUFF( (SELECT ', ' + convert(varchar(10), t2.date, 120) FROM yourtable t2 where t1.id = t2.id FOR XML PATH ('')) , 1,...
STUFF(Original_Expression, Start, Length, Replacement_expression) STUFF() function inserts Replacement_expression, at the start position specified, along with removing the characters specified using Length parameter. Select FirstName, LastName,Email, STUFF(Email, 2, 3, '*****') as StuffedEmail Fr...

Page 1 of 1