- Ensure the date format matches: Verify that the date format in your database matches the format you’re using in the LIKE clause.
- Check for leading/trailing spaces: Ensure there are no leading or trailing spaces in the date strings in your database.
- Verify the column name: Make sure the column name date is correct and matches the column name in your database.
Using 'LIKE' in database explorer to select variables corresponding to substring.
3 ビュー (過去 30 日間)
古いコメントを表示
Right so I have a SQL database that I'm analysing using the database toolbox and I want to select all variables corresponding to a particular date. Problem is that the dates currently include the time that the variable was measured, e.g. '2014-01-01 00:00:00'. I looked online and thought the following should work...
WHERE data.date LIKE '2014-01-01%'
to select variables where data.date starts with '2014-01-01'. When I implement this I don't get an error but nothing seems to be happening. Any ideas? Thanks in advance.
0 件のコメント
回答 (1 件)
Piyush Kumar
2024 年 11 月 26 日
Hi,
The query you have shared should work as expected, selecting all records where the date column starts with ‘2014-01-01’. If you’re not seeing any results, here are a few things to check:
If you still encounter issues, you might want to try using the CONVERT function to ensure the date format is consistent:
SELECT * FROM data WHERE CONVERT(datetime, date, 120) LIKE '2014-01-01%';
This converts the date column to a string in the format ‘yyyy-mm-dd hh:mi:ss’ before applying the LIKE operator.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Database Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!