STUFF string function is a string into another string. The first string of characters that deletes a specified length start position in a string, the second string is then inserted into the start position, the syntax is as follows.
STUFF(<character_expression>,<start>,<length>,<character_expression>)
String 1030, starting from the third position, remove a length of 0, then insert 3 in front of the colon, the output of 10:30.
declare @Time VARCHAR(10) SET @Time = '1030' SELECT STUFF(@Time, 3, 0, ':')
Variable column line, a primary key lookup table separated by commas, return xml string separated by commas.
select ','+cast(QUERY_RECORD_ID as nvarchar(256)) from [CreditCheckICBCE].[dbo].[QUERY_RECORD] where IDENTIFY_TYPE=100 for xml path('')
Remove string and drop the comma, output: 6,7,8,9,10,11,16,17,25,27
select ids= stuff((select top 10 ','+cast(QUERY_RECORD_ID as nvarchar(256)) from [CreditCheckICBCE].[dbo].[QUERY_RECORD] where IDENTIFY_TYPE=100 for xml path('')),1,1,'')
binding splice stuff for xml path string JSON
select json='['+stuff((select ',{"QUERY_RECORD_ID":"'+cast(QUERY_RECORD_ID as nvarchar(256))+'","APPLICANT_NAME":"'+APPLICANT_NAME+'"}' from [CreditCheckICBCE].[dbo].[QUERY_RECORD] where IDENTIFY_TYPE=100 for xml path('')),1,1,'')+']'
Output:
[{ " QUERY_RECORD_ID " : " . 6 " , " APPLICANT_NAME " : " oil Oil Planning and Design " }, { " QUERY_RECORD_ID " : " . 7 " , " APPLICANT_NAME " : " oil Oil Planning and Design " }]