About 778,000 results
Open links in new tab
  1. sql server - How do I perform an IF...THEN in an SQL SELECT?

    Sep 15, 2008 · The CASE statement is the closest to IF in SQL and is supported on all versions of SQL Server. SELECT CAST( CASE WHEN Obsolete = 'N' or InStock = 'Y' THEN 1 ELSE 0 END AS bit) as Saleable, * FROM Product You only need to use the CAST operator if you want the result as a Boolean value. If you are happy with an int, this works: SELECT CASE WHEN …

  2. SQL Server AS statement aliased column within WHERE statement

    Mar 25, 2016 · SQL doesn't typically allow you to reference column aliases in WHERE, GROUP BY or HAVING clauses. MySQL does support referencing column aliases in the GROUP BY and HAVING, but I stress that it will cause problems when porting such queries to other databases. When in doubt, use the actual column name: SELECT t.lat AS latitude FROM poi_table t …

  3. sql server - SQL: IF clause within WHERE clause - Stack Overflow

    Sep 18, 2008 · Is it possible to use an IF clause within a WHERE clause in MS SQL?

  4. SQL Server - In clause with a declared variable - Stack Overflow

    Dec 11, 2014 · You can't use a variable in an IN clause - you need to use dynamic SQL, or use a function (TSQL or CLR) to convert the list of values into a table. Dynamic SQL example:

  5. "IN" clause limitation in Sql Server - Stack Overflow

    Jan 17, 2014 · Does anybody know what is the limit for the number of values one can have in a list of expressions (to test for a match) for the IN clause?

  6. sql - How to use "and" and "or" in a "Where" clause - Stack Overflow

    I have a query that is gathering information based on a set of conditions. Basically I want to know if a location has paid out more than $50 for the day OR the comment section has the word "filter...

  7. How to implement LIMIT with SQL Server? - Stack Overflow

    This is almost a duplicate of a question I asked in October: Emulate MySQL LIMIT clause in Microsoft SQL Server 2000 If you're using Microsoft SQL Server 2000, there is no good solution. Most people have to resort to capturing the result of the query in a temporary table with a IDENTITY primary key.

  8. sql server - Use a calculated column in a where clause - Stack …

    Dec 16, 2014 · I'm trying to use a calculated column in a where clause. I've been trying everything from CROSS APPLY, to sub-query select but it does not give me anything near what I need. My query so far: SELECT p.

  9. sql - Using ROW_NUMBER () function in WHERE clause - Stack …

    I found one question answered with the ROW_NUMBER() function in the where clause. When I tried one query, I was getting the following error: Msg 4108 Level 15 State 1 Line 3 Windowed functions can...

  10. sql - Datetime in where clause - Stack Overflow

    How can I select 12/20/2008 in where clause of sql? The server is SQL server 2005. select * from tblErrorLog where errorDate = '12/20/2008'

Refresh