October 16, 2015 at 10:06 am
Hi
I need to split the amount equally into 12 months from Jan 2015 through Dec 2015.
There is no date column in the table and the total amount has to be splitted equally.
Guess I can't use Pivot here because the date column is not there ...How can I achieve this ?
CREATE TABLE #tbl_data (
Region Varchar(25),
Amount FLOAT,
);
INSERT INTO #tbl_data (
Region,
Amount
)
VALUES
( 'North America',48000),
( 'Asia' ,60000)
Select * from #tbl_data
DROP Table #tbl_data
Output expected will be
Region Jan2015 Feb2015.......Dec2015
NorthAmerica 4000 4000 ......... 4000
Asia 5000 5000 .......... 5000
October 16, 2015 at 10:14 am
You mean like this?
Select Region,
Amount / 12 AS Jan2015,
Amount / 12 AS Feb2015,
--...
Amount / 12 AS Dec2015
from #tbl_data
October 16, 2015 at 10:16 am
sharonsql2013 (10/16/2015)
HiI need to split the amount equally into 12 months from Jan 2015 through Dec 2015.
There is no date column in the table and the total amount has to be splitted equally.
Guess I can't use Pivot here because the date column is not there ...How can I achieve this ?
CREATE TABLE #tbl_data (
Region Varchar(25),
Amount FLOAT,
);
INSERT INTO #tbl_data (
Region,
Amount
)
VALUES
( 'North America',48000),
( 'Asia' ,60000)
Select * from #tbl_data
DROP Table #tbl_data
Output expected will be
Region Jan2015 Feb2015.......Dec2015
NorthAmerica 4000 4000 ......... 4000
Asia 5000 5000 .......... 5000
SELECT
Region,
[Jan2015] = Amount/12,
[Dec2015] = Amount/12
FROM #tbl_data
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
October 16, 2015 at 10:24 am
Oh yes! Thanks
October 16, 2015 at 10:24 am
Thanks:)
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply