Concatenate values based on numeric value of another column [duplicate] - sql

This question already has answers here:
get a comma delimited string from rows [duplicate]
(2 answers)
How to concatenate text from multiple rows into a single text string in SQL Server
(47 answers)
Closed 3 years ago.
I'm trying to concatenate multiple rows of data into one row based off of another column's ordered value
Here's the data that I'm working with:
Here's the data picture
Here's the desired output:
37960 BRAKES GENERAL REPAIRS ADDITIONAL REPAIRS
I'm working in SSMS V14.0 Thanks!

Related

Concatenate multiple rows to one row [duplicate]

This question already has answers here:
Simulating group_concat MySQL function in Microsoft SQL Server 2005?
(12 answers)
SQL Server: Combine multiple rows into one row from a join table?
(1 answer)
ListAGG in SQLSERVER
(4 answers)
how to stuff date and time in SQL
(2 answers)
Query to get multiple row into single row
(3 answers)
Closed 3 years ago.
I have the below data and I have to concatenate the long text column and make it as a single row. The challenge part is only one row has the notification number and other rows are null. You cannot group by the notification number.
I need the output as 2 rows
row number Notification Number Plant Creation Date Language Lineno Tag Long Text
1 10014354914 A057 43466 EN 1 >X aaabbbcccdddeeefffggghhhjjjkkklll
2 10014354915 A057 43466 EN 1 >X aaabbbcccdddeeefffgggpppqqqrrrsss
I have used cursor for this. But it is taking much time.
If you are using oracle:
with data("row number", "Notification Number","Plant","Creation Date","Language","Lineno","Tag","Long Text") as (
select 1,10014354914,'A057',43466,'EN',1,'>X','aaabbbcccdddeeefffggghhhjjjkkklll' from dual
union all
select 2,10014354915,'A057',43466,'EN',1,'>X','aaabbbcccdddeeefffgggpppqqqrrrsss' from dual)
select LISTAGG("Long Text",'') within group (order by "row number") from data;
if you are using ms-sql maybe try this:
SELECT u.[Long Text] AS [text()]
FROM yourtable u
ORDER BY u.[row number]
FOR XML PATH ('')

How to create new column with values counting up every 9th value with SQL? [duplicate]

This question already has answers here:
Group rows into sets of 5
(2 answers)
Closed 3 years ago.
as I realized that my project cannot be implemented with Excel I am now forced to learn working with SQL. Because I'm used to Excel VBA I am already failing at simple tasks.
In a table of my SQL Database I wanna create a new column with values counting up (ASC) but it shouldn't count up like 1,2,3,4,...it rather should increase the value by 1 every 9th value.
So if we start in row 1 with Value 1 than every row until row 9 in this column should countain value 1 followed by an increase in row 10 by 1. So value 2 should be shown until row 18.....in total this should end in row 306.
Is anybody able to help me? I have no clue at all..
THANK YOU FOR YOU HELP!
You can first simply add a column in your table and then update that column with a simple mathematics formula -
UPDATE YOUR_TABLE
SET NEW_COL = CEILING(((ID-1)/9)+1)
Hope this helps.

Its like transpose rows to columns in DB2 while we can't use aggregation [duplicate]

This question already has answers here:
Coalescing values in a column over a partition
(3 answers)
Closed 4 years ago.
I have a table as below
Element Value
State GA
State CA
State IL
And so on ....
I need to transpose above output as follows. It's similar to transposing, but little different as I need comma separated columns.
Element Value
State GA,CA,IL
Can someone help me to achieve above result in db2?
I got the answer with the help of #mustaccio
used listagg function..

BigQuery array intersect [duplicate]

This question already has an answer here:
BigQuery check for array overlap
(1 answer)
Closed 5 years ago.
I have an array of values I'd like to filter results for if an array column contains any of these values, is there an easy way to perform an intersect in BigQuery using the standard SQL language?
This should give you the general direction:
SELECT ...
WHERE EXISTS(SELECT 1 FROM UNNEST(array_column) a WHERE a IN UNNEST(array_values))

Postgres - get count of a chacter in a column? [duplicate]

This question already has answers here:
Counting chars in sequences via SQL
(2 answers)
Closed 7 years ago.
In Postgres/SQL, how can I get the count of a character in a column?
For example, I want to run a query which will return the number of times "X" appears in a column that has the value "XXX" - and it should return 3.
One method is the difference of lengths:
select (length(col) - length(replace(col, 'X', ''))) as NumX