on 03-22-2013 7:55 AM
Hi Experts,
We have a requirement where i need to fetch the current day records from the SQL SERVER 2008. for that i have to write a query in such a way that. it should only fetch the current date records.
Fields to be fetched from the SQL sever are
empCode | EventDate | Event ID |
14566 | 28-01-2012 11:45:54:456 | 616 |
14567 | 29-01-2012 12:10:45:546 | 617 |
14568 | 31-01-2012 10:45::56:845 | 616 |
14569 | 31-01-2012 12:55:32:256 | 216 |
14570 | 01-02-2012 09:32:21:121 | 520 |
Data format for the Event date is : YYYY-MM-DD HH:MM:SS:MS. there is no separate field for the Date.
the other condition is we should only fetch the EventID's which is equal to 616 or 617
so can someone help me with the query.
thank u all...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Bhargava,
You may try the SQL below as an alternative to Venkat's suggestion:
SELECT * FROM [table] WHERE EventDate LIKE DATE_FORMAT (NOW(), '%d-%m-%Y %') AND EventId IN ('616', '617')
Regards,
Koen
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Bhargava,
Try the below.
select * from tablename WHERE CAST(CONVERT(VARCHAR,expirydate,101) AS DATETIME) <= CAST(CONVERT(VARCHAR,GETDATE(),101) AS DATETIME) AND (EventID='616' OR EventID='617')
Execute the above query first in sql server and check whether it is properly working or not .We don't have sql server ,so i haven't checked it.
Regards
Venkat
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.