Since you have not mentioned about any errors, if START_DATE
and END_DATE
are DATETIME
data type, there is nothing wrong with your query. If you are not getting the correct records, Please check the data.
However your date format may trouble you in a different server
. There are some good practices you could adhere to avoid such issues.
-Whenever date is used as a string, try to use it in ISO or ISO8601 format (ie ‘yyyymmdd’ or ‘yyyy-mm-ddThh:mi:ss.mmm’)
-Also avoid joining tables with WHERE Table1, Table2 which is old and obsolete. JOINs are much better performed, neat and tidy.
You can change your query as follows;
SELECT DISTINCT T1.column1, T1.column2, T2.START_DATE, T2.END_DATE FROM Table1 T1 JOIN Table2 T2 ON T1.column1 = T2.column2 WHERE (T2.START_DATE >= '20130115 10:58:58' AND T2.END_DATE <= '20130118 10:58:58') ORDER BY T2.START_DATE DESC
Related Posts:
- Rename column SQL Server 2008
- Efficiently convert rows to columns in sql server
- T-SQL split string based on delimiter
- SQL Server Insert if not exists
- SQL Server: Invalid Column Name
- Determine ROW that caused “unexpected end of file” error in BULK INSERT?
- Determine ROW that caused “unexpected end of file” error in BULK INSERT?
- Microsoft OLE DB Provider for SQL Server error ‘80004005’
- Bulk load data conversion error (truncation)
- Backup a single table with its data from a database in sql server 2008
- How can I group by date time column without taking time into consideration
- Varchar invalid for Sum operator
- Selecting COUNT(*) with DISTINCT
- Case in Select Statement
- What is a stored procedure?
- Conversion failed when converting date and/or time from character string while inserting datetime
- Self Join to get employee manager name
- SQL query to select dates between two dates
- Conversion failed when converting date and/or time from character string while inserting datetime
- When should I use CROSS APPLY over INNER JOIN?
- Insert Data Into Temp Table with Query
- error, string or binary data would be truncated when trying to insert
- How to create Temp table with SELECT * INTO tempTable FROM CTE Query
- NOT IN vs NOT EXISTS
- Must declare the scalar variable
- T-SQL split string
- Nested select statement in SQL Server
- INSERT statement conflicted with the FOREIGN KEY constraint – SQL Server
- How do I escape a single quote in SQL Server?
- How do I escape a single quote in SQL Server?
- How Stuff and ‘For Xml Path’ work in SQL Server?
- Conversion of a varchar data type to a datetime data type resulted in an out-of-range value in SQL query
- Column name or number of supplied values does not match table definition
- Inserting data into a temporary table
- Can a foreign key be NULL and/or duplicate?
- How do I do multiple CASE WHEN conditions using SQL Server 2008?
- CREATE VIEW must be the only statement in the batch
- SQL Server FOR EACH Loop
- Difference between JOIN and INNER JOIN
- Best way to do nested case statement logic in SQL Server
- The multi-part identifier could not be bound
- “CASE” statement within “WHERE” clause in SQL Server 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
- How can I delete using INNER JOIN with SQL Server?
- SQL Server WITH statement
- DateTime2 vs DateTime in SQL Server
- Conversion of a varchar data type to a datetime data type resulted in an out-of-range value in SQL query
- Difference between numeric, float and decimal in SQL Server
- The ALTER TABLE statement conflicted with the FOREIGN KEY constraint
- How can I get column names from a table in SQL Server?
- How do I do multiple CASE WHEN conditions using SQL Server 2008?
- SQL Server reports ‘Invalid column name’, but the column is present and the query works through management studio
- What is the equivalent of ‘describe table’ in SQL Server?
- SQL Server IF NOT EXISTS Usage?
- How do I query for all dates greater than a certain date in SQL Server?
- String or binary data would be truncated. The statement has been terminated
- Add a column with a default value to an existing table in SQL Server
- Error converting data type varchar to float
- Remote table-Valued Function Calls are not allowed
- How to concatenate text from multiple rows into a single text string in SQL Server
- Count(*) vs Count(1) – SQL Server
- Arithmetic overflow error converting numeric to data type numeric
- I want to use CASE statement to update some records in sql server 2005
- The backend version is not supported to design database diagrams or tables
- Conversion failed when converting the varchar value ‘simple, ‘ to data type int
- SELECT DISTINCT on one column
- Exclude a column using SELECT * [except columnA] FROM tableA?
- Why is SQL server throwing this error: Cannot insert the value NULL into column ‘id’?
- TSQL PIVOT MULTIPLE COLUMNS
- Equivalent of Oracle’s RowID in SQL Server
- Is there a Max function in SQL Server that takes two values like Math.Max in .NET?
- sql query to return differences between two tables
- Subtract one day from datetime
- Can I use multiple “with”?
- ‘CREATE PROCEDURE’ must be the only statement in the batch (Erro)
- Is it possible to specify condition in Count()?
- Replacing NULL with 0 in a SQL server query
- SQL Server dynamic PIVOT query?
- Incorrect syntax near ”
- SQL Server: Make all UPPER case to Proper Case/Title Case
- How do I query for all dates greater than a certain date in SQL Server?
- Error converting data type varchar
- I want to use CASE statement to update some records in sql server 2005
- SQL Server “cannot perform an aggregate function on an expression containing an aggregate or a subquery”, but Sybase can
- Get everything after and before certain character in SQL Server
- Cannot create an instance of OLE DB provider Microsoft.Jet.OLEDB.4.0 for linked server null
- ORDER BY items must appear in the select list if SELECT DISTINCT is specified
- Solutions for INSERT OR UPDATE on SQL Server
- What are database constraints?
- Arithmetic overflow error converting varchar to data type numeric. ’10’ <= 9.00
- How to select the last record of a table in SQL?
- Inner Joining three tables
- “select * into table” Will it work for inserting data into existing table
- INSERT VALUES WHERE NOT EXISTS
- SUM OVER PARTITION BY
- How to implement LIMIT with SQL Server? [duplicate]
- Update query using Subquery in Sql Server
- Cannot insert explicit value for identity column in table ‘table’ when IDENTITY_INSERT is set to OFF
- How to dump a Microsoft SQL Server database to a SQL script?