Skip to content
Advertisement

Tag: rows

SQL get rows to colums only for 1 row. Pivot not possible

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

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

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

Advertisement