
How do I perform an IF...THEN in an SQL SELECT?
Sep 15, 2008 · SELECT CASE WHEN Obsolete = 'N' or InStock = 'Y' THEN 1 ELSE 0 END as Saleable, * FROM Product CASE statements can be embedded in other CASE statements and even included …
SQL Server SELECT into existing table - Stack Overflow
I am trying to select some fields from one table and insert them into an existing table from a stored procedure. Here is what I am trying: SELECT col1, col2 INTO dbo.TableTwo FROM dbo.TableOne W...
Nested select statement in SQL Server - Stack Overflow
SELECT name FROM (SELECT name FROM agentinformation) as a We need to make an alias of the subquery because a query needs a table object which we will get from making an alias for the …
mysql - 'IF' in 'SELECT' statement - choose output value based on ...
SELECT id, amount FROM report I need amount to be amount if report.type='P' and -amount if report.type='N'. How do I add this to the above query?
SQL "select where not in subquery" returns no results
Sep 10, 2009 · The long answer (From T-SQL Fundamentals, Third edition, by Itzik Ben-Gan) This is an example: Imagine there is a order with a NULL orderid inside Sales.Orders table, so the subquery …
SQL select * from column where year = 2010 - Stack Overflow
Apr 28, 2016 · This is probably a simple where clause but I want to say, from columnX (which is datetime) I want all rows where just the year = 2010. so: select * from mytable where Columnx =
sql - Counting DISTINCT over multiple columns - Stack Overflow
Sep 24, 2009 · SELECT COUNT(*) FROM (SELECT DISTINCT DocumentId, DocumentSessionId FROM DocumentOutputItems) AS internalQuery I need to count the number of distinct items from …
SQL: Two select statements in one query - Stack Overflow
Aug 13, 2015 · I want to select information from two SQL tables within one query, the information is unrelated though, so no potential joints exist. An example could be the following setup. tblMadrid id | n...
sql - MySQL SELECT only not null values - Stack Overflow
Is it possible to do a select statement that takes only NOT NULL values? Right now I am using this: SELECT * FROM table And then I have to filter out the null values with a php loop. Is there a ...
sql - Exclude a column using SELECT * [except columnA] FROM tableA ...
We all know that to select all columns from a table, we can use SELECT * FROM tableA Is there a way to exclude column(s) from a table without specifying all the columns? SELECT * [except columnA]...