Questions tagged [stuff]

The STUFF function inserts a string into another string. It deletes a specified length of characters in the first string at the start position and then inserts the second string into the first string at the start position.

Filter by
Sorted by
Tagged with
-1 votes
1 answer
49 views

STUFF function along with charIndex() in sql server

I need to display a table column (assume 2 columns) values with comma-separated in the output Table t1: col1 Col2 ================ xyz ab/cde pqr uv/wxy xyz fg/hij lmn ...
Padmaja's user avatar
  • 111
-2 votes
2 answers
65 views

Group By with Multiple Stuff Statements - SQL

I am trying to aggregate multiple rows into a single field (for multiple columns), grouped by a common ID (See below) This is the what I have ID CPT SVCDate Vendor 1 A3A 1/14/2023 A 2 ...
ND_OG_89's user avatar
0 votes
1 answer
177 views

SQL Query slow only when Row_Number values are used in STUFF

I have a fairly basic SQL query which runs in 1 second without the Data_1 field which is performing a STUFF() and using RN for filter and order. With the Data_1 field in the query the execution goes ...
JetRocket11's user avatar
-3 votes
2 answers
150 views

Substitute for Function STUFF (SQL Server) in AWS redshift

I have to replace first 3 digits of a column to a fix first 3 digits (123) Working SQL Server code. (Not working on AWS RedShift) Code: Select Stuff (ColName,1,3,'123')as NewColName From DataBase.dbo....
MeghJeet's user avatar
0 votes
1 answer
29 views

Stuff() Not Grouping Accurately

I am using an older version of SQL Server and trying to convert rows to concatenated columns. From researching here on stack overflow I see that I should be using STUFF(). However, when I attempt to ...
JayA's user avatar
  • 19
1 vote
2 answers
103 views

Order by on specific id in subquery with STUFF()

I am using SQL Server and facing problem to get my required data. Here is my sample table: Date PlayID Name City 11/20/2022 101 Rishi Mumbai 11/20/2022 102 Smita New Mumbai 11/21/2022 102 Maiyand ...
Rahul Chaudhari's user avatar
0 votes
0 answers
40 views

Multiple case expression and stuff functions in select statement cause very bad performance

I'm trying to combine multiple rows and multiple columns into one column. I've a table like below: Parent table: ID Name 1 A 2 B Child table: ID Score1 Score2 Remark1 Remark2 1 0 0 ...
xChaax's user avatar
  • 193
1 vote
2 answers
314 views

SQL STUFF FOR XML with specific grouping

I'm working in SQL Server 2014, and I have the following simple data, which tracks calling history of users: PhoneNumber Activity ActivityDate ------------------------------------ 9075551234 ...
Depth of Field's user avatar
0 votes
0 answers
80 views

Stuff function returns null values

When i am trying the stuff function in this query: select Project.* from TimePayrollTimesheet3 tp inner join (SELECT t1.parentrecordID, abc = STUFF ( (SELECT ',' + ...
shweta's user avatar
  • 11
-2 votes
1 answer
459 views

SQL Server STUFF query with the SAME table

I need to get the result like this: I have tried using this query: SELECT STUFF((SELECT ', ' + CONVERT(VARCHAR(50), RuleNumber) FROM #tempSelectPlusReferralsExtracts v2 ...
Kapil's user avatar
  • 1,833
0 votes
0 answers
190 views

Why selecting STUFF value decrease performance of a query in SQL Server

Recently I want to improve some of my queries and I see something that I don't really understand, here is my query : SELECT S.VENTE_GUID, Top6QtySold.list FROM SALES s with(nolock) OUTER ...
ElRoro's user avatar
  • 213
0 votes
1 answer
88 views

Replace character in EUR amount

First post so hope I include the right stuff, apologies if not. I have a mix of currency amounts Im importing into a database. Some of them are EUR and as such swap the "," and "." ...
SFish1980's user avatar
1 vote
3 answers
78 views

SQL tagging - Returning new column in results

I need to create a new column for my query labeled Tags There are three tags and the definitions are below: Metro: City = Chicago Mailing: ACNT = 'ACT' Greeting: Salutation in ('Ms.','Mrs.') Current ...
Toby's user avatar
  • 135
2 votes
0 answers
52 views

After adding Feature Name and Feature Value query takes more than 5 minutes

I work on SQL Server 2014 and my issue occurred after displaying Feature Name and Feature Value separated by $. When executing the query below after adding Feature Name and Feature Value with stuff it ...
abeer shlby's user avatar
0 votes
1 answer
254 views

What is the best way to replicate the STUFF() function from T-SQL in PL/SQL?

I'm trying to replicate the behavior of the STUFF() function from Transact SQL in Oracle. I assume both the CONCAT and SUBSTR functions will be involved, but I can't figure out a clever way to do it ...
Seyi's user avatar
  • 9
0 votes
1 answer
83 views

How to order by nulls-last by a linked table

I have two tables Person and PersonSkill Person ID NAME 1 Person 1 2 Person 2 3 Person 3 PersonSkill PERSON_ID SKILL SORT 1 Sing 20 1 Playful 10 2 Sing 10 1 Bowl 30 1 SQL 40 I'm trying to ...
Jeggy's user avatar
  • 1,474
0 votes
1 answer
228 views

Replace XML Path Stuff Query

I would like to replace the following query as I have performance problems. The execution plan is giving me a lot of redisual due to Table Spool operators (Lazy Spool) SELECT DISTINCT LOT_0, VarCode =...
Jose Navarro's user avatar
0 votes
2 answers
761 views

Need to add double quotes to SQL SERVER string values

I have integer values that are being passed from a parameter that needed to be input as a string and padded so that they are 7 digits. This will then be passed into another query. declare @t table(...
jackstraw22's user avatar
0 votes
1 answer
56 views

Combining Multiple Rows into 1 Row (but twice)

My query looks like this: SELECT req.number , task.number , usr.vendor FROM req LEFT JOIN task on req.sys_id = task.req_item LEFT JOIN usr on usr.sys_id = task.assigned_to Results look ...
Chrissy Scott's user avatar
1 vote
1 answer
935 views

Select distinct with order by in stuff function

I would like to know if its possible to reorder the concatenated cells in stuff function based on another column. As of now, I am using below query SELECT Id, KPI = STUFF((SELECT DISTINCT ', ...
Justin Matthew Tacogue's user avatar
-1 votes
1 answer
132 views

How to fetch values using STUFF Function in SQL Server

I am using the below code which is giving me no. of Orders each month but I want to stuff order no.s in each month column. Ord Ref Month Party Name Name of Item Order 1 Jun Vendor 1 Item A Order 2 ...
Clink Digital Content You Shou's user avatar
1 vote
2 answers
9k views

Concatenate SQL columns with comma separated

Is there any alternate way to concatenate SQL columns with comma separated. I am using below logic for concatenation. The columns (col1,col2,col3) can have null values. select stuff( left(...
MRR's user avatar
  • 83
-1 votes
1 answer
1k views

STUFF FOR XML PATH - combine multiple rows into a single column cell

Let's say I have data in a table that looks like this Num1 Type1 Type2 Acct Ind --- ---- ---- --- --- 1X2 XXX CA ...
Koosh's user avatar
  • 876
1 vote
2 answers
164 views

T-SQL - only stuff / concatenate some columns and drop xml

I have a table like this: ID C1 C2 seq 1 This is my re ally long sentence 1 1 This is my re stored in a 2 1 This is my re really terrible format 3 And I need some SQL query or stored procedure to ...
Bob Fishel's user avatar
0 votes
1 answer
293 views

Is there a way in the STUFF(... FOR XML) function in SQL to prevent duplicate values?

To keep this short, here's my SQL code: SELECT EmailAddress, FormsSubmitted = STUFF( ( SELECT ',' + SourceSubType FROM UK_AGT_AgentForms_TEST_DE a WHERE a....
Mike Marks's user avatar
0 votes
0 answers
255 views

How can we extract the value from a stuff function variable for processing

Hello I would like to know how can we assign the value of a column to a variable in SQL server 2012 For example consider the below scenario in which I retrieve the record id and emails (multiple ...
John George's user avatar
0 votes
2 answers
670 views

Convert the data, split rows into columns in SQL

Could you please help me in displaying the table output in below format. Table data Required output
MRR's user avatar
  • 83
1 vote
0 answers
53 views

After adding a function to use a renamed file, the program won't find the text string anymore

Okay, the title may be a bit vague. I honestly don't even know how to phrase the question. The program tries to find a string of text inside a file, and then print the entire line that the string is ...
Mew's user avatar
  • 25
0 votes
1 answer
299 views

SQL Query to group by time and roll up and concatenate string values

I am trying to get a particular format from a group of times and days between two tables. Database: MeetingTime table has a relationship from MeetingTime.DayOfWeekId (foreign key) to table DayOfWeek....
cmartin's user avatar
  • 2,819
-1 votes
3 answers
157 views

T-SQL - using STUFF to concatenate grouped columns and removing duplicates

I have a table that looks like this: EmailAddress: nvarchar(255) MarketingEmailOptIn: nvarchar(50) NewsletterOptIn: nvarchar(50) ThoughtLeaderOptIn: nvarchar(50) My SQL statement shown below takes ...
Mike Marks's user avatar
0 votes
1 answer
330 views

How can i avoid a multiple using stuff for xml path?

I'm having a problem with sql query. What i'm trying to do is to get list of stores with tasks assigned on users in it. Each role in separated column with user names. I'm using STUFF from getting ...
Denis Mishin's user avatar
0 votes
2 answers
478 views

SQL Server 2016: Use FOR XML and STUFF with Multiple Join Query

I have a query made for reporting purposes to list out employers that have not submitted quarterly reports and to list out the quarters that haven't been submitted. This is my query: with employerIds ...
BGonzaga's user avatar
0 votes
1 answer
151 views

What is the symbol/s for spacebar press when using the `screen stuff` command?

I have a screen command as such.. screen -S sessionname -X stuff 'spacebar' I want to replace "spacebar" with the appropriate symbol/s to emulate a spacebar press. I would also like to know ...
deanresin's user avatar
  • 1,469
0 votes
1 answer
392 views

“Stuff and 'For Xml Path'” or UNION to exclude duplicate rows

This is further progress of question here: how to use "Stuff and 'For Xml Path'" to unite rows in table I have 3 tables - invoices, positions and accounts which build common table by ...
user421875's user avatar
1 vote
2 answers
4k views

how to use "Stuff and 'For Xml Path'" to unite rows in table

Please help me to get united rows and list of accounts separated by commas in table. I don't quite understand how to use "Stuff and 'For Xml Path'" for it. This is my query: CREATE TABLE ...
user421875's user avatar
0 votes
2 answers
479 views

SQL SERVER: concatenate node values of XML column

I have the following table that holds a column which is in XML: Id Label Details 1 Test1 <terms><destination><email>[email protected]</email><email>[email protected]</...
lai's user avatar
  • 1,163
0 votes
1 answer
1k views

Concatenate comma separated strings using STUFF

I want to concatenate comma-separated string. I have a query where I am using the function to get the staff. Currently, I am using [dbo].fn_fullname(A.REFNO) as Staff to get the staff but I want to ...
Aarav's user avatar
  • 3
1 vote
1 answer
76 views

SQL server query to search and stuff multiple rows

I have table employee_table which is like this org employeeid (int) firstname lastname 1234 56788934 Suresh Raina 1234 56793904 Virat Kohli then i have ...
curiousboy's user avatar
1 vote
1 answer
194 views

String aggregate in legacy in sql server

I have this table grid_id | criteria_id | start_value| end_value | provider | property1 | property2 | property3 --------|-------------|------------|-----------|----------|-----------|-----------|------...
White_Noise's user avatar
1 vote
2 answers
165 views

Create comma separated value strings using data from different tables in SQL Server

I have the following database model: criteria table: criteria_id criteria_name is_range 1 product_category 0 2 product_subcategory 0 3 items ...
Frey_ja's user avatar
  • 41
0 votes
1 answer
311 views

How to return blank or null record when using STUFF and XML PATH on SQL Server 2016?

I am using STUFF and XML PATH as it is obligatory that I use SQL Server 2016. I have been working on this query and I cannot figure out how to return null or blank record when using STUFF and XML PATH....
Yashi Vaidehi Arya's user avatar
0 votes
1 answer
333 views

Use STUFF() on a result set coming from OPENJSON

I have a ClassTable as shown below with a Languages column in which the data is in JSON: ID Title Languages 1 Class1 [{"ID": 1, "Name": "English"},{"ID": 2, &...
Suhas Mandumale's user avatar
-1 votes
1 answer
916 views

Using the STUFF function in update

Can someone tell me why this use of the STUFF function will not work? UPDATE table SET STUFF(address, LEN(TRIM(address)) - 2, 2, 'Drive') WHERE RIGHT(TRIM(address), 3) =' DR' Is it because the insert ...
jack_humphrey's user avatar
0 votes
2 answers
391 views

T-SQL MS SQL Stuff. How to combine rows into single row with group by

I have a SQL Query: SELECT [B].[Id] ,[B].[CreateDate] ,[Author] ,[B].[WorkcenterId] ,[B].[AreaId] ,[B].[SubAreaId] ,[B].[Description] ,[PriorityId] ,[...
MatR's user avatar
  • 225
0 votes
1 answer
506 views

String split ,sort and compare with another column within a table SQL

Create Table #temp ( Change varchar(20), deleted_user_id int, deleted_field_id int, deleted_value nvarchar (4000), inserted_user_id int, inserted_field_id int, inserted_value nvarchar (4000), ...
Rocky3151's user avatar
1 vote
2 answers
48 views

How to separate unique values respective to its row using STUFF and FOR XML PATH

I'm running this query: SELECT A.PeripheralNumber, P.LoginName, P.FirstName, P.LastName, A.EnterpriseName, A.AgentDeskSettingsID, AttributeValues = STUFF((SELECT ',' + ATT.EnterpriseName+'='+AT....
aquamelli's user avatar
491 votes
8 answers
853k views

How Stuff and 'For Xml Path' work in SQL Server?

Table is: Id Name 1 aaa 1 bbb 1 ccc 1 ddd 1 eee Required output: Id abc 1 aaa,bbb,ccc,ddd,eee Query: SELECT ID, abc = STUFF( (SELECT ',' + name FROM temp1 FOR XML PATH (...
Puneet Chawla's user avatar