| Author |
Topic |
|
baska123
Yak Posting Veteran
64 Posts |
Posted - 2007-05-04 : 16:53:02
|
| How to changemonth_abbrev like '2007%' to read the systems date select only year part of it and use it in a like statement?Thanks |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-05-04 : 16:56:02
|
| month_abbrev like Year(Getdate()) + '%'Dinakar NethiSQL Server MVP************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
|
baska123
Yak Posting Veteran
64 Posts |
Posted - 2007-05-04 : 17:10:14
|
| Looks goodI need to convert it to nvarchar too. |
 |
|
|
baska123
Yak Posting Veteran
64 Posts |
Posted - 2007-05-04 : 17:13:39
|
| onvertedAm I correctmonth_abbrev like cast(Year(Getdate()) as nvarchar) + '%' |
 |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-05-04 : 17:20:16
|
| Yeah..Dinakar NethiSQL Server MVP************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-05-05 : 03:10:48
|
quote: Originally posted by baska123 How to changemonth_abbrev like '2007%' to read the systems date select only year part of it and use it in a like statement?Thanks
If you need only year part, then why dont you use Year(datecol)=2007?MadhivananFailing to plan is Planning to fail |
 |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-05-05 : 11:00:28
|
quote: Originally posted by madhivanan
quote: Originally posted by baska123 How to changemonth_abbrev like '2007%' to read the systems date select only year part of it and use it in a like statement?Thanks
If you need only year part, then why dont you use Year(datecol)=2007?MadhivananFailing to plan is Planning to fail
Madhiusing functions on columns could negate the use of indexes.Dinakar NethiSQL Server MVP************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-05-07 : 06:11:05
|
| Well if that is the case, then your example also wont make use of index. Right?MadhivananFailing to plan is Planning to fail |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-05-07 : 06:17:15
|
| No, Madhivanan.Because dinakar is not wrapping function around a column, but on GETDATE().Also, OP doesn't seem to have datetime column as he is using LIKE comparison. so Year(datecol) won't work.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-05-07 : 07:58:04
|
Thanks. I missed to notice Getdate(). I understand now MadhivananFailing to plan is Planning to fail |
 |
|
|
jshepler
Yak Posting Veteran
60 Posts |
Posted - 2007-05-07 : 21:45:43
|
| Doesn't LIKE negate the use of indexes?/jeff |
 |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-05-07 : 23:24:32
|
quote: Originally posted by jshepler Doesn't LIKE negate the use of indexes?/jeff
It would if its like LIKE '%something' but not if its like LIKE 'something%' Dinakar NethiSQL Server MVP************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
|
|