
How to stack data with SQL Server
Mar 20, 2013 · If you are using SQL Server 2008+, then you can use CROSS APPLY with VALUES: select t.uid, t.id1, t.id2, c.variable, c.value from YourTable t cross apply ( values ('var1', t.var1), ('var2', t.var2), ('var3', t.var3) ) c (variable, value); See SQL Fiddle with Demo Thanks @Lamak for the fiddle
Newest 'sql' Questions - Stack Overflow
In SQL, I have a customer table and an orders table and based on what quantity a customer orders I want to give them a percentage discount. For example, three customer below. Cust 1 receives a 10% ...
SQL WITH clause example - Stack Overflow
Sep 23, 2012 · The SQL WITH clause was introduced by Oracle in the Oracle 9i release 2 database. The SQL WITH clause allows you to give a sub-query block a name (a process also called sub-query refactoring), which can be referenced in several places within the main SQL query. The name assigned to the sub-query is treated as though it was an inline view or table.
What is a SQL JOIN, and what are the different types?
What is SQL JOIN? SQL JOIN is a method to retrieve data from two or more database tables. What are the different SQL JOINs ? There are a total of five JOINs. They are : 1. JOIN or INNER JOIN 2. OUTER JOIN 2.1 LEFT OUTER JOIN or LEFT JOIN 2.2 RIGHT OUTER JOIN or RIGHT JOIN 2.3 FULL OUTER JOIN or FULL JOIN 3. NATURAL JOIN 4.
Stacking multiple tables in SQL server - Stack Overflow
I am essentially trying to do a UNION all on multiple tables and have the result be a new table. I know that I can do this to select and stack all of the rows: SELECT * FROM table1 UNION ALL SELEC...
Understanding PIVOT function in T-SQL - Stack Overflow
I am very new to SQL. I have a table like this: ID TeamID UserID ElementID PhaseID Effort 1 1 1 3 5 6.74 2 1 1 3 6 8.25 3 1 1 4 1 2.23 4 1 1 4 5 6.8 5 1 1 4 6 1.5 And I was told to get data like this
exception - Oracle PL/SQL: how to get the stack trace, package …
Sometimes the exception returns something like: "ORA-06502: PL/SQL: numeric or value error: character string buffer too small". It's not so readable since it doesn't report neither the table, the ...
sql - What is the difference between PARTITION BY and GROUP BY …
The SQL GROUP BY clause can be used in a SELECT statement to collect data across multiple records and group the results by one or more columns. In more simple words GROUP BY statement is used in conjunction with the aggregate functions to …
sql - What is a stored procedure? - Stack Overflow
Dec 31, 2019 · Stored procedures in SQL Server can accept input parameters and return multiple values of output parameters; in SQL Server, stored procedures program statements to perform operations in the database and return a status value to a calling procedure or batch. The benefits of using stored procedures in SQL Server. They allow modular programming.
Should I use != or <> for not equal in T-SQL? - Stack Overflow
Apr 6, 2009 · Yes; Microsoft themselves recommend using <> over != specifically for ANSI compliance, e.g. in Microsoft Press training kit for 70-461 exam, "Querying Microsoft SQL Server", they say "As an example of when to choose the standard form, T-SQL supports two “not equal to” operators: <> and !=. The former is standard and the latter is not.