Click here to Skip to main content
15,896,269 members
Home / Discussions / Database
   

Database

 
GeneralRe: Need last bit of help with a view being built Pin
Michael J. Eber5-Apr-10 19:43
Michael J. Eber5-Apr-10 19:43 
GeneralRe: Need last bit of help with a view being built Pin
Mycroft Holmes5-Apr-10 19:53
professionalMycroft Holmes5-Apr-10 19:53 
QuestionHow To fetch records from xlsheet Pin
raghvendrapanda5-Apr-10 1:53
raghvendrapanda5-Apr-10 1:53 
AnswerRe: How To fetch records from xlsheet Pin
Eddy Vluggen5-Apr-10 22:08
professionalEddy Vluggen5-Apr-10 22:08 
QuestionUndo Restore in Sql 2005 Pin
Abdul Rahman Hamidy4-Apr-10 19:34
Abdul Rahman Hamidy4-Apr-10 19:34 
AnswerRe: Undo Restore in Sql 2005 Pin
Mycroft Holmes5-Apr-10 1:36
professionalMycroft Holmes5-Apr-10 1:36 
AnswerRe: Undo Restore in Sql 2005 Pin
T21026-Apr-10 14:22
T21026-Apr-10 14:22 
QuestionSorting Pivot results Pin
Andy_L_J2-Apr-10 13:01
Andy_L_J2-Apr-10 13:01 
Given the following Query, I get the desired results, however, the result set is sorted on the PLine Column.

I would like to Order By the ID Column, or Better yet, the Factory.Factory_No (varChar), ProdnLine.ProdnLine_No (int)columns.

DECLARE @LineKgs Table(
           ID Int, PLine VarChar(7),kgs Decimal(18,7), TDate nVarChar(10))

INSERT INTO @LineKgs
  SELECT  f.Factory_No + '/' + CAST(pl.ProdLine_No As VarChar), pl.ProdLine_ID,
          mt.Qty, CAST(month(mt.TransDate) AS VArChar(10))
  
  FROM Production pr
    LEFT OUTER JOIN ProdLine pl
      ON pl.ProdLine_ID = pr.ProdLine_ID
    JOIN MaterialTransaction mt
      ON pr.Prodn_ID = mt.Prodn_ID
    JOIN Factory f
      ON pl.Factory_ID = f.Factory_ID
   WHERE mt.TransDate BETWEEN '1/1/2010' AND '12/31/2010'   
 
 SELECT ID, PLine, [1] As Jan, [2] As Feb, [3] As Mar, [4] As Apr,
            [5] As May, [6] As Jun, [7] As Jul, [8] As Aug,
            [9] As Sep, [10] As Oct, [11] As Nov, [12] as Dec
     FROM( SELECT ID, PLine, kgs, TDate
         
      FROM @LineKgs) p2
      PIVOT(SUM(kgs)
         FOR TDate In ([1], [2],[3],[4],[5],[6],
                       [7],[8],[9],[10],[11],[12])) As P


Current Result
ID	PLine	Jan	Feb	Mar      ...  
=============================================    
1	Fac1/1	8497	60012	19503    ...
2	Fac1/2	104772  152379	33795
3	Fac1/3	76338	113653	40742
4	Fac1/4	197339	333348	118314
5	Fac1/5	200986	363314	106225
6	Fac1/6	35048	189619	44345
7	Fac1/7	45632	133981	52921
8	Fac1/8	58387	185468	39916
9	Fac1/9	34625	76026	69479
10	Fac2/1	420	4150	828
19	Fac2/10	10816	25213	2681
20	Fac2/11	13680	30765	4597
21	Fac2/12	10576	NULL	19068
11	Fac2/2	251	333	NULL
12	Fac2/3	433	1536	NULL
...


Desired Result:
ID	PLine	Jan	Feb	Mar      ...  
=============================================    
1	Fac1/1	8497	60012	19503    ...
2	Fac1/2	104772  152379	33795
3	Fac1/3	76338	113653	40742
4	Fac1/4	197339	333348	118314
5	Fac1/5	200986	363314	106225
6	Fac1/6	35048	189619	44345
7	Fac1/7	45632	133981	52921
8	Fac1/8	58387	185468	39916
9	Fac1/9	34625	76026	69479
10	Fac2/1	420	4150	828
11	Fac2/2	251	333	NULL
12	Fac2/3	433	1536	NULL
...
20	Fac2/11	13680	30765	4597
21	Fac2/12	10576	NULL	19068
...


As always, your guidance is most appreciated.
I don't speak Idiot - please talk slowly and clearly

'This space for rent'

Driven to the arms of Heineken by the wife

AnswerRe: Sorting Pivot results Pin
Mycroft Holmes2-Apr-10 13:18
professionalMycroft Holmes2-Apr-10 13:18 
GeneralRe: Sorting Pivot results Pin
Andy_L_J2-Apr-10 14:33
Andy_L_J2-Apr-10 14:33 
QuestionSSIS - Ignore Duplicate Records while Doing Data Flow. Pin
codeproject_Tarun2-Apr-10 4:44
codeproject_Tarun2-Apr-10 4:44 
AnswerRe: SSIS - Ignore Duplicate Records while Doing Data Flow. Pin
Andy_L_J2-Apr-10 13:07
Andy_L_J2-Apr-10 13:07 
QuestionSQL Server - what is the best to move a database between to another computer Pin
LouWilk2-Apr-10 3:26
LouWilk2-Apr-10 3:26 
AnswerRe: SQL Server - what is the best to move a database between to another computer Pin
scottgp2-Apr-10 3:49
professionalscottgp2-Apr-10 3:49 
AnswerRe: SQL Server - what is the best to move a database between to another computer Pin
St_Pierce2-Apr-10 4:04
St_Pierce2-Apr-10 4:04 
QuestionI Think I May Go Back To MS Access Pin
Roger Wright1-Apr-10 18:26
professionalRoger Wright1-Apr-10 18:26 
AnswerRe: I Think I May Go Back To MS Access Pin
Mycroft Holmes1-Apr-10 23:17
professionalMycroft Holmes1-Apr-10 23:17 
GeneralRe: I Think I May Go Back To MS Access Pin
Roger Wright2-Apr-10 2:45
professionalRoger Wright2-Apr-10 2:45 
AnswerRe: I Think I May Go Back To MS Access Pin
Gonzoox2-Apr-10 3:55
Gonzoox2-Apr-10 3:55 
GeneralRe: I Think I May Go Back To MS Access Pin
Roger Wright2-Apr-10 16:22
professionalRoger Wright2-Apr-10 16:22 
AnswerRe: I Think I May Go Back To MS Access - Solution Found! Pin
Roger Wright2-Apr-10 18:29
professionalRoger Wright2-Apr-10 18:29 
GeneralRe: I Think I May Go Back To MS Access - Solution NOT Found! Pin
Luc Pattyn2-Apr-10 18:35
sitebuilderLuc Pattyn2-Apr-10 18:35 
GeneralRe: I Think I May Go Back To MS Access - Solution Found! Pin
Roger Wright2-Apr-10 19:24
professionalRoger Wright2-Apr-10 19:24 
GeneralRe: I Think I May Go Back To MS Access - Solution NOT Found! Pin
Luc Pattyn2-Apr-10 19:40
sitebuilderLuc Pattyn2-Apr-10 19:40 
GeneralRe: I Think I May Go Back To MS Access - Solution Almost Found! Pin
Roger Wright2-Apr-10 20:07
professionalRoger Wright2-Apr-10 20:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.