I’m using SQL Server. Looking for similar functionality as GROUP_CONCAT or listagg functions provided in other Databases. Seems like STUFF function is provided to concat rows. Here’s my attempt. Employee Role EmployeeRole Expected Output Answer In SQLServer 2017, you can use aggregate function STRING_AGG(): Note: table aliases make the query more concise and easier to read. I modified the query
Tag: string
Provide the values for a ‘like’ function from a specific column in a Table?
I am using SQL Server 2014 and I need a T-SQL query which uses the like function to run on a specific column (c1) of a Table (t1) to find out if it contains one of the codes from a list of codes found …
Find the count of words in string
SQL: How to find the count of words in following example? Subquestions: How to count spaces? How to count double/triple/… spaces as one? answer by Gordon Linoff here How to avoid counting of special characters? Example: ‘Please , don’t count this comma’ Is it possible without string_split function (because it’s available only since SQL SERVER 2016)? Summary with the best
VBA Function/ Code – Convert Dynamic Column of Data into Text String
I’m creating a tool where users can query an ODBC through excel. I need a function which will look at a column of item id’s which the user has pasted in and then create a text string which can be used …
How can i merge two columns of a table in sql as a sentence?
i am a beginner in database programming. I am doing my homework, and i get a task about sql queries. My task is to merge 3 columns(first name, last name, sex) of a table(person) in a sentence. for …
Extract a specific value from a string in a column
Need help with a situation, I need to extract a specific value from a column containing string. The string varies over different records, but the value I need to extract is always preceded by the word “VERSION” I tried to user REVERSE & SUBSTRING but not able to get exact results. Any help will be greatly appreciated the table looks
Selecting all foreign rows for each row useing a N-N table
I have a N-N table, lets say as an example Teachers and Subjects: There is a Teacher table as follows: There is a Subject table as follows: And there is a TeacherTeachesSubject as follows: Only that each table has more than 10000 entries. I need to make a query which returns me something like this: What I am doing right
What is the best way to compare a name field with a string value?
I have a query that compares a string value against a name field in my database. The structure of the name field in the DB is not consistent, it could be any of these: John Doe Doe John Doe, John My …
Split a string into two fields based on multiple words
I have the following column in my Table name:STAT It would be helpful if someone can assist in writing a mysql script I would like to split the strings in to 2 columns. However the split should happen only based on the last word, i.e the Region as can be seen in the example below. There is an exception that
How to add a character to specific index in string
I have a db with email-addresses which are 15 characters in total. Some are 14 characters long and they have the same in common, they miss a 0 in their name at the 3th index. I had a what similar …