Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date help needed

Status
Not open for further replies.

ddrafts

IS-IT--Management
Dec 26, 2002
119
US
I'm not that good with SQL but I'm doing my best. I have been looking for over a week on how to do this but I cannot figure it out. I want the Closed Date and Time to just be the month. How or can this be done?

Code:
SELECT Incident."Incident #", Incident."Open Date & Time", Incident."Close Date & Time", Incident.Escalation, Incident."Priority:", Incident."Group Name", Incident."Department ID"
FROM {oj SDE."GAO NOTIFICATION".Incident Incident LEFT OUTER JOIN SDE.EXTERNAL_SUPPORT."Groups Details" "Groups Details" ON Incident."Open By Group" = "Groups Details".Sequence}
WHERE (Incident."Open Date & Time" Between {ts '2007-03-01 00:00:01'} And {ts '2007-03-31 00:00:01'}) AND (Incident."Group Name"='CLIENT SERVICES')
ORDER BY Incident."Close Date & Time", Incident.Escalation

Thanks in advance
Doug
 
Doug -

Check out these queries. I think they will show you what to do, depending on your specific need.

Code:
[COLOR=green]--get a date/time value
[/color][COLOR=blue]select[/color] [COLOR=#FF00FF]getdate[/color]()

[COLOR=green]--get numeric representation of month
[/color][COLOR=blue]select[/color] [COLOR=#FF00FF]datepart[/color]([COLOR=#FF00FF]month[/color], [COLOR=#FF00FF]getdate[/color]())

[COLOR=green]--get name of month
[/color][COLOR=blue]select[/color] [COLOR=#FF00FF]datename[/color]([COLOR=#FF00FF]month[/color], [COLOR=#FF00FF]getdate[/color]())

Hope this helps,

Alex

Ignorance of certain subjects is a great part of wisdom
 
Alex,

Thank you so much. what I ended up with was
Code:
SELECT Incident."Incident #", Incident."Open Date & Time", datename(month,convert(datetime,Incident."Close Date & Time")), Incident.Escalation, Incident."Priority:", Incident."Group Name", Incident."Department ID"
FROM {oj SDE."GAO NOTIFICATION".Incident Incident LEFT OUTER JOIN SDE.EXTERNAL_SUPPORT."Groups Details" "Groups Details" ON Incident."Open By Group" = "Groups Details".Sequence}
WHERE (Incident."Open Date & Time" Between {ts '2007-03-01 00:00:01'} And {ts '2007-03-31 00:00:01'}) AND (Incident."Group Name"='CLIENT SERVICES')
ORDER BY Incident."Close Date & Time", Incident.Escalation

It now works like I need it to.
 
Are you storing dates as VARCHAR data type? If you aren't and its' a date-time column, you shouldn't need the convert. Of course, if they are varchar, you do need it. Just a thought.

Glad you got it working :)

Alex

Ignorance of certain subjects is a great part of wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top