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 2000 Forums
 SQL Server Administration (2000)
 sql query using only month and year

Author  Topic 

Keshaba
Yak Posting Veteran

52 Posts

Posted - 2009-01-16 : 08:24:06
I am using sql server 2005 as back-end .I want to write a sql query
using only month and year And day to be excluded. If i want to search
all list of Items from October-2008 to December-2009 .Then how shall
i write the query.The Month is in Full format like October,no short
cut used to name month

Keshab

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-01-16 : 09:19:29
See http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-16 : 09:21:45
what all values will you input?
Go to Top of Page

Keshaba
Yak Posting Veteran

52 Posts

Posted - 2009-01-21 : 08:38:04
Okay I am writing a simple query to explain my problem .

select tabsetting.EmpCode from tabsetting where Month(tabsetting.Pdate) ='October' And Year(tabsetting.Pdate) = '2008'

The above query is okay.But I have to break the Pdate into 2 parts
as you can see in the query one part to get month and the other
for Year.
Can't I write the query without breaking the Pdate.


For furthur explaination of the problem

select Convert(Varchar(12), GetDate(), 112)

Here for date format we can change the numbers
Style ID Style Type
0 or 100 mon dd yyyy hh:miAM (or PM)
101 mm/dd/yy
102 yy.mm.dd
103 dd/mm/yy
104 dd.mm.yy
105 dd-mm-yy
106 dd mon yy
107 Mon dd, yy
108 hh:mm:ss
9 or 109 mon dd yyyy hh:mi:ss:mmmAM (or PM)
110 mm-dd-yy
111 yy/mm/dd
112 yymmdd
13 or 113 dd mon yyyy hh:mm:ss:mmm(24h)
114 hh:mi:ss:mmm(24h)
20 or 120 yyyy-mm-dd hh:mi:ss(24h)
21 or 121 yyyy-mm-dd hh:mi:ss.mmm(24h)
126 yyyy-mm-dd Thh:mm:ss.mmm(no spaces)
130 dd mon yyyy hh:mi:ss:mmmAM
131 dd/mm/yy hh:mi:ss:mmmAM


But to get only MMMM-yyyy like October-2008 December-2008 do we have
any special date format like above

Keshab
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-01-21 : 09:11:27
quote:
But to get only MMMM-yyyy like October-2008 December-2008 do we have
any special date format like above


No, You'll have to use datename function for that.

Something like

select datename(month,getdate())+'-'+datename(year,getdate())
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-21 : 11:24:15
why cant you make month and year as two parameters and just use them in where clause after taking month and year values from field using datepart()
Go to Top of Page
   

- Advertisement -