Reputation: 47
I have a SQL-Server database in which I want to get the data from the column VL_DR between two given dates and where the date is a Friday.
"SELECT VL_DR FROM table_VL WHERE date>='" + date_start
+ "' AND date<='" + date_end
+ "' AND DATENAME(dw, date)='Friday'"
But after the request I have an empty list while I should have some values. What should I fix to get the correct request?
Upvotes: 1
Views: 5735
Reputation: 5808
If its SQL Server
Try
SELECT VL_DR FROM table_VL WHERE ([date] BETWEEN date_start and date_end) AND LOWER(DATENAME(dw, [date]))='friday'
If its MySQL
Try
SELECT VL_DR FROM table_VL WHERE ([date] BETWEEN date_start and date_end) AND DAYNAME([date])='Friday'
Upvotes: 3
Reputation: 1750
This code will work, based on data in a Share Code database that I have. This is for MS-SQL.
SELECT
CloseDate, DatePart(WEEKDAY,CloseDate) AS DAY_OF_WEEK_No , SharePrice
FROM
SharePrice
WHERE
CloseDate BETWEEN '01 October 2014' AND '31 October 2014'
AND
DATEPART(WEEKDAY,CloseDate) = 6 -- 1=Sunday; 7=Saturday
AND
ShareCode = 'AGL'
Upvotes: 0
Reputation: 2780
Assuming MySQL. DAYNAME
should work
"SELECT VL_DR FROM table_VL WHERE date>='" + date_start
+ "' AND date<='" + date_end
+ "' AND DAYNAME(date)='Friday'"
Example:
SELECT DAYNAME('2008-05-15');
results Thursday
Upvotes: 0