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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing smalldatetime to day of weekdaynumber T-SQL??

Status
Not open for further replies.

joethehoe

Technical User
Jan 2, 2002
27
US
Hello ALL :) I'm new to SQL and I'm trying change the results of my query to a week day number instead of a smalldate: (IE SUNDAY would 1. and monday 2) I know its a datefirst function but I'm unable to get the correct syntax ??

DECLARE @begin smalldatetime,
@end smalldatetime

SET @begin = '08/11/03'
SET @end = '08/11/03'

SELECT J.jobdate,
AZ_Time = CASE AU.[sysName]
WHEN 'Ratbert' THEN RIGHT('0' + CAST(CAST(LEFT(AU.tdTime,2) as int)-2 as varchar) + RIGHT(AU.tdTime,6),8)
WHEN 'Dogbert' THEN RIGHT('0' + CAST(CAST(LEFT(AU.tdTime,2) as int)-2 as varchar) + RIGHT(AU.tdTime,6),8)
ELSE AU.tdTime
END,
SUM(AU.jobClock)/3600 AS jobClock
FROM Analyst.mo_agent_unit
AS AU INNER JOIN
Analyst.mo_job
AS J ON J.[sysName] = AU.[sysName] AND
J.jobNum = AU.jobNum
WHERE (CAST(J.jobDate as datetime) BETWEEN @begin AND @end) and
(j.jobName like 'AG3%')and au.agentID LIKE 'w%'
GROUP BY J.jobDate,
CASE AU.[sysName]
WHEN 'Ratbert' THEN RIGHT('0' + CAST(CAST(LEFT(AU.tdTime,2) as int)-2 as varchar) + RIGHT(AU.tdTime,6),8)
WHEN 'Dogbert' THEN RIGHT('0' + CAST(CAST(LEFT(AU.tdTime,2) as int)-2 as varchar) + RIGHT(AU.tdTime,6),8)
ELSE AU.tdTime
END
ORDER BY J.jobDate, AZ_Time
 
Not sure what bit in that uber select you are referring to - however:

from BOL ( for DATEPART:

use DATEPART(dw, someDatetimeValue) to get a number 1 to 7 representing day of the week :)

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top