Results 1 to 19 of 19

Thread: Help with SQL statement

Hybrid View

  1. #1
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    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

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jan 2005
    Posts
    138

    Re: Help with SQL statement

    Quote 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

  3. #3
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Help with SQL statement

    Quote 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.

    Quote 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

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jan 2005
    Posts
    138

    Re: Help with SQL statement

    Quote 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
  •  



Click Here to Expand Forum to Full Width