tags:

views:

53

answers:

1

my query is showing in row 2000 the data of 2000-2001 & in 2001 the data of 2001-2002. how can i change the column so that it displayes

column 1        column 2
2000-2001         5
2001-2002         3
2002-2003         9
2003-2004         12
.
.
.
.

and so on...

A: 

Without seeing your query this will have to be very generic, but something like the following should work:

SELECT TO_CHAR(col1) || '-' || TO_CHAR(col1+1) as "column 1",
       col2 as "column 2"
  FROM (SELECT col1,
               SUM(col2) as col2
          FROM sometable
          WHERE something = something_else
          GROUP BY col1)

The above is Oracle syntax (the TO_CHAR and || string concatenations) but should give you a good idea of how to proceed.

EDIT: In SQL Server try the following:

SELECT CAST(col1 AS NVARCHAR(100)) + N'-' +
                                    CAST(col1+1 AS NVARCHAR(100)) AS "column 1",
       col2 as "column 2"
  FROM (SELECT col1,
               SUM(col2) as col2
          FROM sometable
          WHERE something = something_else
          GROUP BY col1)

Share and enjoy.

Bob Jarvis
it doesnt solve my problem...nywayz thanx
jasmeet
If you could post the query you're currently using we might be able to offer more assistance.
Bob Jarvis
jasmeet, if it doesn't solve the problem, please explain why it doesn't. What do you expect? And what do you have so far?
chiccodoro