|
-
Mar 14th, 2006, 04:38 PM
#1
Re: Help with SQL statement
Here's a 'One-pass' method
Note: I had to do this on SQLServer and I think you need a & rather than a + to concat string fields in Oracle.
Code:
SELECT DEPT
,SUM(AMOUNT)
FROM DK_TEST
WHERE CAST(CAST(MYYEAR AS CHAR(4))+ CAST([WEEK] AS CHAR(2))AS INT)
BETWEEN 200512 AND 200601
GROUP BY
DEPT
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Mar 14th, 2006, 04:43 PM
#2
Thread Starter
Addicted Member
Re: Help with SQL statement
 Originally Posted by DKenny
Here's a 'One-pass' method
Note: I had to do this on SQLServer and I think you need a & rather than a + to concat string fields in Oracle.
Code:
SELECT DEPT
,SUM(AMOUNT)
FROM DK_TEST
WHERE CAST(CAST(MYYEAR AS CHAR(4))+ CAST([WEEK] AS CHAR(2))AS INT)
BETWEEN 200512 AND 200601
GROUP BY
DEPT
If I may call upon you help again, what does CAST stands for? Also would the CHAR(2) take care of the 0 in front of single digit week number?
Tx
-
Mar 14th, 2006, 04:47 PM
#3
Re: Help with SQL statement
 Originally Posted by D-niss
If I may call upon you help again, what does CAST stands for?
CAST is use to change the Type of a value.
Synthax:
CAST( Value as Type)
So CAST(MYYEAR AS CHAR(4)) converts the values in the field MYYEAR to a fixed length string, 4 characters long.
 Originally Posted by D-niss
Also would the CHAR(2) take care of the 0 in front of single digit week number?
Tx
Yes, the CHAR datatype is fixed length, and casting an Integer as a CHAR will always add preceding zeros.
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Mar 14th, 2006, 04:51 PM
#4
Thread Starter
Addicted Member
Re: Help with SQL statement
 Originally Posted by DKenny
CAST is use to change the Type of a value.
Synthax:
CAST( Value as Type)
So CAST(MYYEAR AS CHAR(4)) converts the values in the field MYYEAR to a fixed length string, 4 characters long.
Yes, the CHAR datatype is fixed length, and casting an Integer as a CHAR will always add preceding zeros.
ahhh this is beautifull, I love it. I will try it soon and let you guys know. At first sight, it seems this will do the job.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|