Why not something simple like the following?
WHERE (X = 1 AND Y = 2) OR (X = 5 AND Y = 6) ...
Or, if you’re looking for rows (based on your example) where Y should be X + 1, then:
WHERE Y = X + 1
If you have thousands of OR
clauses like the above, then I would suggest you populate a criterion table ahead of time, and rewrite your query as a join. Suppose you have such a table Criteria(X, Y)
then your query becomes much simpler:
SELECT Table.* FROM Table INNER JOIN Criteria ON Table.X = Criteria.X AND Table.Y = Criteria.Y
Don’t forget to add an index / foreign keys as necessary to the new table.
If for some reason you prefer to not create a table ahead of time, you can use a temporary table or table variable and populate it within your procedure.
Related Posts:
- Inserting multiple rows in a single SQL query? [duplicate]
- SQL query to get the employee name and their manager name from the same table
- T-SQL split string
- The SQL OVER() clause – when and why is it useful?
- Update multiple columns in SQL
- SQL Server IF EXISTS THEN 1 ELSE 2
- SQL Query with SUM with Group By
- How do I perform an IF…THEN in an SQL SELECT?
- SQL update from one Table to another based on a ID match
- Conversion of a varchar data type to a datetime data type resulted in an out-of-range value in SQL query
- How to drop all tables from a database with one SQL query?
- SQL Server : Arithmetic overflow error converting expression to data type int
- How to calculate percentage with a SQL statement
- Query comparing dates in SQL
- What is the meaning of the prefix N in T-SQL statements and when should I use it?
- Query error with ambiguous column name in SQL
- How to drop all tables from a database with one SQL query?
- How to find sum of multiple columns in a table in SQL Server 2005?
- How can I delete using INNER JOIN with SQL Server?
- Conversion of a varchar data type to a datetime data type resulted in an out-of-range value in SQL query
- CREATE TABLE IF NOT EXISTS equivalent in SQL Server
- How to group by month from Date field using sql
- How can I get column names from a table in SQL Server?
- Is there a combination of “LIKE” and “IN” in SQL?
- Search text in stored procedure in SQL Server
- How to format a numeric column as phone number in SQL
- sql query to return differences between two tables
- SQL: IF clause within WHERE clause
- How to select the last record of a table in SQL?
- SQL- Ignore case while searching for a string
- Using Excel VBA to run SQL query
- What is tableName.* in SQL
- Case in Select Statement
- What do Clustered and Non-Clustered index actually mean?
- Self Join to get employee manager name
- How do I UPDATE from a SELECT in SQL Server?
- SQL query to select dates between two dates
- NOT IN vs NOT EXISTS
- How can I do an UPDATE statement with JOIN in SQL Server?
- Must declare the scalar variable
- Must declare the scalar variable
- INSERT statement conflicted with the FOREIGN KEY constraint – SQL Server
- INSERT statement conflicted with the FOREIGN KEY constraint – SQL Server
- How do I escape a single quote in SQL Server?
- Drop a temporary table if it exists
- Data source name not found, and no default driver specified
- IDENTITY_INSERT is set to OFF – How to turn it ON?
- An attempt was made to access a socket in a way forbidden by its access permissions
- Each GROUP BY expression must contain at least one column that is not an outer reference
- Optimistic vs. Pessimistic locking
- Can a foreign key be NULL and/or duplicate?
- Why does NULL = NULL evaluate to false in SQL server
- When to use SELECT … FOR UPDATE?
- Best way to do nested case statement logic in SQL Server
- BCP error “Unable to open BCP host data-file”
- How can I clone an SQL Server database on the same server in SQL Server 2008 Express?
- “CASE” statement within “WHERE” clause in SQL Server 2008
- Get day of week in SQL Server 2005/2008
- What is the difference between Scope_Identity(), Identity(), @@Identity, and Ident_Current()?
- incorrect syntax error CREATE VIEW must be the only statement in the batch
- SQL Server : error converting data type varchar to numeric
- Why use a READ UNCOMMITTED isolation level?
- SQL Server reports ‘Invalid column name’, but the column is present and the query works through management studio
- How to parse XML data in SQL server table
- How to convert SQL Server’s timestamp column to datetime format
- What is the equivalent of ‘describe table’ in SQL Server?
- Remote table-Valued Function Calls are not allowed
- MS SQL compare dates?
- The backend version is not supported to design database diagrams or tables
- Determine ROW that caused “unexpected end of file” error in BULK INSERT?
- Determine ROW that caused “unexpected end of file” error in BULK INSERT?
- The SELECT permission was denied on the object ‘Users’, database ‘XXX’, schema ‘dbo’
- How do you open an SDF file (SQL Server Compact Edition)?
- What is the maximum characters for the NVARCHAR(MAX)?
- Get size of all tables in database
- Exclude a column using SELECT * [except columnA] FROM tableA?
- Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1, column 4 (Year)
- Why is SQL server throwing this error: Cannot insert the value NULL into column ‘id’?
- Bulk load data conversion error (truncation)
- How do I fix the multiple-step OLE DB operation errors in SSIS?
- SQL Server: Error converting data type nvarchar to numeric
- SQL “select where not in subquery” returns no results
- ListAGG in SQLSERVER
- How do I format a number with commas in T-SQL?
- ‘CREATE PROCEDURE’ must be the only statement in the batch (Erro)
- To add server using sp_addlinkedserver
- How to connect to a local database in SQL Server Management Studio?
- How to calculate age (in years) based on Date of Birth and getDate()
- Solutions for INSERT OR UPDATE on SQL Server
- Text was truncated or one or more characters had no match in the target code page including the primary key in an unpivot
- How can I group by date time column without taking time into consideration
- What are named pipes?
- SHOWPLAN permission denied in database ‘tempdb’. in sql server 2008
- Append table to an existing one: SQL Server
- SQL Server – An expression of non-boolean type specified in a context where a condition is expected, near ‘RETURN’
- “select * into table” Will it work for inserting data into existing table
- INSERT VALUES WHERE NOT EXISTS
- CASE IN statement with multiple values
- How to implement LIMIT with SQL Server? [duplicate]
- Update query using Subquery in Sql Server