Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2005 SQL-Server , +
Hello,
 
I am doing one application for filtering records according to filter entered by user.
I have one drop down list for filter types and one text box for filter string.
Filter conditions in drop down lists are :
?*, *?*, =, !=, >, >=, <, <=, etc
 
And i think end user will put following valid values in text box-
2013/04/04
April 2013
2013
07 Apr 2013
07 Apr
12:00
11:30 PM
 
My database table have following field-
uploaded_on (smalldatetime)
 
I have to write query such that whatever filter entered by user is, records should be filtered according to that.
 
Thanks.
Posted 7-Apr-13 0:39am
Edited 7-Apr-13 0:40am
v2
Comments
OriginalGriff at 7-Apr-13 5:41am
   
And?
What have you tried?
Where are you stuck?
Sonal Wagh at 7-Apr-13 5:47am
   
I mean how do i write multiple cases to match the filter format user entered with format in database.
e.g. when input id Apr 2012, the output will contain all dates with month April, 2012
when input is 24, all dates with date 24 will be displayed, etc.
Sonal Wagh at 7-Apr-13 5:49am
   
I can easily achieve this by writing multiple queries for each case, but i want to write those in single query.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Please, read about datetime and smalldatetime data types[^] for MS SQL Server.
 
Try to convert:
SELECT CONVERT(SMALLDATETIME, '12:00') AS MyDateTime
and see what happens.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 315
1 OriginalGriff 273
2 Aajmot Sk 224
3 Marcin Kozub 210
4 Richard MacCutchan 200
0 OriginalGriff 7,853
1 Sergey Alexandrovich Kryukov 7,107
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,790


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 7 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100