Do you have any idea on how to display values obtained by concat_group in multiple columns instead of having a unique column containing all the values separated by commas.
Thanks in advance :-)
You cannot do this in SQL.
One of the fixed rules of SQL is that the columns in your select-list must be set at the time you prepare your query. The select-list does not expand dynamically to match the values it finds as it examines the data.
This comes from the origins of SQL in the relational model. A relation (not a relationship, lots of people get this wrong) is a data structure with a fixed set of columns, a header defining the names and data types of the columns, and then a set of rows, where every row has the same set of columns as the header.
The select-list of an SQL SELECT statement effectively defines the header of the relation returned as the result-set of that query. The number and names of the columns are defined by the query, not by the data in the result.
A commenter above asks if you want to do a pivot, but a pivot also requires that you name the columns in the select-list. There is no such thing as a SQL pivot query that grows its select-list according to the data in the result.
Related
IS there a way in SQL to make multiple rows for a common column, show up in one?
For example I would like this output:
to show up as:
I believe this article contains solutions to your question -
SQL Query to concatenate column values from multiple rows in Oracle
I am using SSAS Tabular model and I want to sort my table using two columns, how can I do that? I can sort it using one column, but I couldn't find a way to sort the table with multiple columns.
From your question, it sounds like you want to apply a general sort order to the entire table? This is not possible in SSAS Tabular. When you sort a column within SSDT, this is only for preview purposes, as the order of rows in the table does not matter when you execute a DAX query against the model. You can, however, specify a sort order for individual columns, based on another column. If you intend to sort a column on two or more columns, read on. If your intention was to have the result of a DAX query be sorted in a specific ways, simply use the ORDER BY clause.
Sorting a column based on two or more columns
A column in a table can be sorted by any one other column. If you need to sort a column by two or more columns, create a composite column and then use that for sorting.
For example, say your table contains columns named [SortPrimary] and [SortSecondary]. Create a new (calculated) column with the expression: MyTable[SortPrimary] & "|" & MyTable[SortSecondary]. Make sure to concatenate the columns using a character that doesn't appear in either column.
I have two tables that store two sets of ID's which are the same, when any of the four ID's are NULL there's an issue on the front end application. These four values always vary as to which can be NULL but there will always be one with the correct entry.
My question is can I enter these four values into a temp table then update all the NULL values using the column which has actually has a value? As the column with the correct value changes all the time it makes it harder.
Basically i'm making a stored proc but can't figure this logic out.
It sounds like you just need to use coalesce to find the non-NULL value.
coalesce(table1.col1, table1.col2, table2,col1, table2.col2)
The only caveat is that if two columns have different non-NULL values, then this expression returns the first one (in the order you list the columns) it finds. But if you don't have that situation occur, or if you can specify which column you'd use when it does occur, this should work regardless of what combination of columns has NULL.
Using table expression to join two tables then from the result table, update the column missing data with the ones have.
First off: I am reverse engineering SQL queries and as a result I have a bunch of candidate queries, which all contain a designated 'entity' column in their SELECT clause.
The problem is: I want the entity column to be the first column of my result and let all the other columns follow, so basically I want something like this
SELECT A.entity, *
FROM A
...
...but without the duplicate entity column resulting from the *-operator.
EDIT: I also do not know all of the column names, generally only the entity column name is known.
Thanks for helping me
We have a huge table and one of the column contains queries like e.g. in row 1
1. (((firstname:Adam OR firstname:Neil ) AND lastname:Lee) ) AND category:"Legal" AND type:Individual
and in row 2 of same column
2. (((firstname:Adam* OR firstname:Neil ) AND lastname:Lee) ) AND category:"Legal" AND type:Organization
Similarly there are few other types of Query strings which are used eventually to query external services.
Issue is based on certain criteria I have to group and remove duplicates from this table.
There are few rules to determine grouping of Strings in different rows.One of them is that if first name and lastname are same then ignore category and type values, therefore above two rows will be grouped to one. There are around million rows. Comparing Strings and doing grouping is not looking elegant solution. What could be best possible solution using sql.