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 |
|
Todd2006
Starting Member
18 Posts |
Posted - 2007-01-28 : 11:26:18
|
| have a field called sigdate datatype varchar that saves dateslike these01/2/200712/2/200706/19/200701/21/2007i want to show distinct months/year in a drop downso the query should output01/200712/2/200706/2007here is my code SELECT Distinct(convert(varchar(2),month([sigdate]))+convert(varchar(4),year([sigdate]))) as [monthyear] from stdregbut its not workingany ideastodd |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-01-28 : 11:47:07
|
| [code]SELECT DISTINCT DATEADD(Month, DATEDIFF(Month, 0, [sigdate]), 0)FROM stdreg[/code]or[code]SELECT DATEADD(Month, DATEDIFF(Month, 0, [sigdate]), 0), COUNT(*)FROM stdregGROUP BY DATEADD(Month, DATEDIFF(Month, 0, [sigdate]), 0)[/code]will give you the date of the first day of the month. You could then format that to get rid of the "day" bit if necessary.Kristen |
 |
|
|
Todd2006
Starting Member
18 Posts |
Posted - 2007-01-28 : 13:32:58
|
| Thanks for ur replyI want the month/year alsoso the query you posted will give the monthi want it like this01/2007month/yearany ideatodd |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-28 : 15:00:38
|
| SELECT datename(month, [sigdate]) + '/' + datename(year, [sigdate]) COUNT(*)FROM stdregGROUP BY datename(month, [sigdate]) + '/' + datename(year, [sigdate])Peter LarssonHelsingborg, Sweden |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-01-28 : 15:25:52
|
| "I want the month/year alsoso the query you posted will give the month"You didn't try it then?It gives the 1st of each month, as I said; so that includes the Month and the Year that you require. You can format the result using CONVERT, or better still using your Client-side application.Kristen |
 |
|
|
|
|
|
|
|