September 20, 2011 at 11:13 pm
I need help on converting the results of my query into single record and insert it to temp table
Here is the result of my select statement;
INV_DATE BILLED
Apr 2011 27907.95
Mar 2011 43441.83
Feb 2011 38554.06
Jan 2011 37737.66
Dec 2010 38490.78
I have a fix number of columns for my #table and the result should be like this.
Month1 Bill1 Month2 Bill2 Month3 Bill3 Month4 Bill4 Month5 Bill5
Apr 2011 27907.95 Mar 2011 43441.83 Feb 2011 38554.06 Jan 2011 37737.66 Dec 2010 38490.78
Thanks in advance.
create table #tempAllan
(Month1 varchar(20),
Billed1 money,
Month2 varchar(20),
Billed2 money,
Month3 varchar(20),
Billed3 money,
Month4 varchar(20),
Billed4 money,
Month5 varchar(20),
Billed5 money
)
insert into #tempAllan
SELECT TOP 5 SUBSTRING(convert(VARCHAR(11), invdapfrom,113),4,100) AS INV_DATE, invncurchg AS BILLED FROM TBLINV
WHERE invccusid = '25512'
AND invcmode = 'INVSV'
ORDER BY invddoi DESC
September 21, 2011 at 12:37 am
good article here
http://www.sqlservercentral.com/articles/T-SQL/63681/
________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply