Stored procedure has 2 date parameters: I have to output the year-months per column in this selection. I extracted a string with all these months: Output is a single column with @cols in it, but what I need is (in this case) 12 columns with first column [2020-01], second column [2020-02] etc. (@cols is not static, it varies with the
Tag: rows
SQL: exclude rows that are duplicates according to some column arrangement
In my problem, I have these rows e.g.: They show pair-wise combinations of ids and names, together with another column c. I consider row 1+2, and 3+4 as duplicates, considering the pairings of ids and names. Rows 1+2, or 3+4 show basically the same information. I had no luck removing the duplicates with grouping, because id1 + id2, or name1
how to make the datagridview load faster with Multiple Row query – c# SQL
The code: The SSMS output: The output form loads slowly, the rows for the query are over 1000 so I think the cause of the slow load is the number of returned rows? If yes, how do make the load of the datagridview faster? Answer NOTE – this answer relates to the first part of the original question regarding why
SQL – Consolidate and group records from multiple rows to columns
Is there a way to transpose multiple rows and group them to columns? I have a table that has data from Invoice values from different tables and columns. Now, I want to have them by Invoice numbers. InvoiceNumber Table Column Value 123 A Column A1 ABC 123 A Column A2 DEF 123 A Column A3 GHI 123 B Column B1
Break ranges into rows Teradata
I have an input like this: I would link to break each range into rows: I’m trying to get this output in TERADATA, can you guys help me? Thanks a lot. Answer Teradata’s proprietary EXPAND ON syntax is for creating time series, but can used for your task, too. Assuming TD16.20+ this can be further simplified using a time series
Pivoting rows to columns with custom column names in SQL Server
I’m having some difficulty with pivoting rows into columns as I also want to name the columns. Here is my current code, modified: And my current output: Just for the sake of shortness, I replaced the actual Message with longmessage1 above. My desired output: The maximum amount of greetings is six, and if a Message doesn’t have six, I’m fine
Omit certain characters from Rows in SQL
I have a column that has Serial Numbers but some of them has unwanted characters attached with the Serial Number:- These are some of the entries from a Column in a SQL Table. I want to omit all the characters including and after the Underscore. For example, these values would become this:- 8558088363_AAC = 8558088363 7272505721_R2C = 7272505721 And keep
SQL sum grouped by field with all rows
I have this table: I want this result: I tried this: But get the error that subquery returns different number of rows. How can I do it? I want all the rows of sale_lines table selecting all fields and adding the sum(price) grouped by sale_id. Answer You can use window function : If you want sub-query then you need to
Split Row and Paste to Different Tables Based on Column
I have a table like this. Table is populated each time an order is complete. One order can have one or many compartments. Please help write an SQL script that takes the above and splits it into two new tables like so: Table 1 Table 2 I’ve tried using the DISTINCT command as suggested; Which returns the error; Subquery returned
Get previous and next row from rows selected with (WHERE) conditions
For example I have this statement: This statement is splitted by word, like this table: I want to get previous and next word of each word For example I want to get previous and next word of “name”: How could I get this result? Answer you didn’t specify your DBMS, so the following is ANSI SQL: SQLFiddle: http://sqlfiddle.com/#!12/7639e/1