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.
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 queryusing 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 monthKeshab |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-16 : 09:21:45
|
what all values will you input? |
|
|
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 numbersStyle ID Style Type0 or 100 mon dd yyyy hh:miAM (or PM)101 mm/dd/yy102 yy.mm.dd103 dd/mm/yy104 dd.mm.yy105 dd-mm-yy106 dd mon yy107 Mon dd, yy108 hh:mm:ss9 or 109 mon dd yyyy hh:mi:ss:mmmAM (or PM)110 mm-dd-yy111 yy/mm/dd112 yymmdd13 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:mmmAM131 dd/mm/yy hh:mi:ss:mmmAM But to get only MMMM-yyyy like October-2008 December-2008 do we haveany special date format like aboveKeshab |
|
|
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 haveany special date format like above
No, You'll have to use datename function for that.Something like select datename(month,getdate())+'-'+datename(year,getdate()) |
|
|
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() |
|
|
|
|
|