| Author |
Topic |
|
sheetal_sarode
Starting Member
4 Posts |
Posted - 2008-12-08 : 03:04:46
|
| Hi All,I have one table (OJDT) which has reddate field having datetime datatype. I want to write query on this table and check the condition on refdate.I tried the following queryselect transid from OJDT where convert(varchar(12),refdate,103) >= '01/12/2008' and convert(varchar(12),refdate,103) <= '31/12/2008'but the result shows all data in the table.Can anyone help to convert date to character format?thanks & Regards,Sheetal |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-12-08 : 03:06:08
|
Why are you converting a datetime to a STRING?select transid from OJDT where refdate >= '01/12/2008' and refdate < '01/01/2009' E 12°55'05.63"N 56°04'39.26" |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-08 : 03:18:18
|
just in case you pass parameter for start & end it will as fiollowsselect transid from OJDT where refdate >= @Start and refdate < DATEADD(dd,1,@end) |
 |
|
|
sheetal_sarode
Starting Member
4 Posts |
Posted - 2008-12-08 : 03:33:55
|
| Hi,If I donot convert to string I get error message as out of range values. start & end parameters will be key in by the user. SO I have to convert them to String.Thanks & Regards,Sheetal |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-08 : 03:38:06
|
quote: Originally posted by sheetal_sarode Hi,If I donot convert to string I get error message as out of range values. start & end parameters will be key in by the user. SO I have to convert them to String.Thanks & Regards,Sheetal
how are you passing date values through param? in what format? is parameter varchar or datetime? |
 |
|
|
sheetal_sarode
Starting Member
4 Posts |
Posted - 2008-12-08 : 03:42:39
|
| I am passing parameters in dd/mm/yyyy format. This parameter is varchar. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-08 : 04:01:28
|
try running this before your querySET DATEFORMAT dmy |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-12-08 : 04:17:32
|
Why are you using VARCHAR parameters for a DATETIME column? E 12°55'05.63"N 56°04'39.26" |
 |
|
|
sheetal_sarode
Starting Member
4 Posts |
Posted - 2008-12-08 : 04:52:51
|
| please suggest me which parameters should I use? |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-12-08 : 04:55:32
|
DATETIME data type parameters. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
|