Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 DATE

Author  Topic 

baska123
Yak Posting Veteran

64 Posts

Posted - 2007-05-04 : 16:53:02
How to change

month_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 Nethi
SQL Server MVP
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

baska123
Yak Posting Veteran

64 Posts

Posted - 2007-05-04 : 17:10:14
Looks good
I need to convert it to nvarchar too.
Go to Top of Page

baska123
Yak Posting Veteran

64 Posts

Posted - 2007-05-04 : 17:13:39
onverted
Am I correct
month_abbrev like cast(Year(Getdate()) as nvarchar) + '%'
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-05-04 : 17:20:16
Yeah..

Dinakar Nethi
SQL Server MVP
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-05-05 : 03:10:48
quote:
Originally posted by baska123

How to change

month_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?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

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 change

month_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?

Madhivanan

Failing to plan is Planning to fail



Madhi

using functions on columns could negate the use of indexes.

Dinakar Nethi
SQL Server MVP
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

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?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

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 Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-05-07 : 07:58:04
Thanks. I missed to notice Getdate(). I understand now

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jshepler
Yak Posting Veteran

60 Posts

Posted - 2007-05-07 : 21:45:43
Doesn't LIKE negate the use of indexes?

/jeff
Go to Top of Page

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 Nethi
SQL Server MVP
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page
   

- Advertisement -