Click here to Skip to main content
16,012,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am a New ASP.NET Developer and I am trying to develop a simple suggestion box system. I have the following part of my database desing:

> User Table: Username, Name, DivisionCode... etc
>
> Division Table: SapCode, Division
>
> SuggestionLog Table: ID, Title, Description, submittedDate, Username

***(The first attribute is the primary key in each table and the attribute (submittedDate) is of DateTime data type)***

Now, I need to develop a table that shows suggestions for the last three months. I already developed a query that shows the Employee Name, Username, Division, Suggestion Title, Suggestion Description. All what I want now is to show the Month. For example, to show the suggestions for the last three months, the Month column should show: Jan-2012, Dec-2011, Nov-2011 **So how to do that?**

My current SQL query:

SQL
SELECT     dbo.SafetySuggestionsLog.Title, dbo.SafetySuggestionsLog.Description, dbo.SafetySuggestionsType.Type, dbo.SafetySuggestionsLog.Username, 
                          dbo.employee.Name, dbo.Divisions.DivisionShortcut
    FROM         dbo.Divisions INNER JOIN
                          dbo.employee ON dbo.Divisions.SapCode = dbo.employee.DivisionCode INNER JOIN
                          dbo.SafetySuggestionsLog ON dbo.employee.Username = dbo.SafetySuggestionsLog.Username INNER JOIN
                          dbo.SafetySuggestionsType ON dbo.SafetySuggestionsLog.TypeID = dbo.SafetySuggestionsType.ID


The desired output is to display:

**Employee Name, Username, Division, SuggestionTitle, SuggstionDescription, SuggestionType Month(submissionDate)**
Posted

hi there...
try this in ur query, just add in your select statement

SQL
SELECT REPLACE(RIGHT(CONVERT(VARCHAR(11),GETDATE(),106),8),' ','-') AS 'MonthDate'




now u will get like mar-2012,feb-2012,jan-2012
Hope this helps..
plz revert back with ur comments...
 
Share this answer
 
v2
Include the clause CONVERT(CHAR(4), submittedDate, 100) + "-" + CONVERT(CHAR(4), submittedDate, 120) in the select part of your query. This will give you the appropriate formatted values.
 
Share this answer
 
Comments
matrix388 26-Feb-12 1:51am    
it doesn't work with me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900