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

Database

 
QuestionRe: How to get the varbinary value from SQLServer2005 and display that string in WebForm? Pin
pmarfleet25-Feb-08 2:10
pmarfleet25-Feb-08 2:10 
Questiontable datatype in sp sql server Pin
Sonia Gupta24-Feb-08 23:04
Sonia Gupta24-Feb-08 23:04 
GeneralRe: table datatype in sp sql server Pin
Joe25-Feb-08 1:06
Joe25-Feb-08 1:06 
GeneralFinding Database name Pin
alok_2k324-Feb-08 19:59
alok_2k324-Feb-08 19:59 
GeneralRe: Finding Database name Pin
Giorgi Dalakishvili24-Feb-08 20:14
mentorGiorgi Dalakishvili24-Feb-08 20:14 
GeneralRe: Finding Database name Pin
alok_2k324-Feb-08 20:23
alok_2k324-Feb-08 20:23 
GeneralRe: Finding Database name Pin
Giorgi Dalakishvili24-Feb-08 20:25
mentorGiorgi Dalakishvili24-Feb-08 20:25 
GeneralQuery result not as expected [modified] Pin
Andy_L_J23-Feb-08 17:35
Andy_L_J23-Feb-08 17:35 
I am attempting to get a result set from a query and it is not how I expected. (Go figure!)

Tables Structure:

Production: Date, WOID (FK)

WorkOrder: WOID (PK), ProdID (FK)

Product: ProdID (PK), PCatID (FK)

Category: PCatID (PK), Category

FormTrans: Date, WOID (FK), Kgs

I want to return results in the following Table structure:

Date, CategoryA, CategoryC, CategoryC,..., CategoryN, Date Kgs, Ave, Running Total


I have tried the following:

DECLARE @Start DateTime,
@End DateTime

SET @Start = '01/01/2007'
SET @End = '12/31/2007'

Select Distinct(pr.[Date],
Case When pc.Category IN ('Mini','Maxi','OSCS')
Then SUM(ft.Kgs)
Else 0
End As 'DUCT',
Case When pc.Category IN ('DSPETG','DSPVC')
Then SUM(ft.Kgs)
ELSE 0
END AS 'DS",
SUM(ft.Kgs) As 'Kgs' -- Date Kgs
-- Average for distinct date required here?
-- Running Total for Dates here?
FROM Production pr
JOIN WorkOrder wo
ON pr.WOID = wo.WOID
JOIN Product p
ON wo.ProdID = p.ProdID
JOIN ProdCategory pc
ON p.PCatID = pc.PCatID
JOIN Formula f
ON wo.FormulaID = f.FormulaID
JOIN FormTrans ft
ON ft.FormulaID = f.FormulaID

WHERE pr.[Date] BETWEEN @Start AND @End
GROUP BY pr.[Date],pc.Category
ORDER BY pr.Date

1, When I run this I am getting data but a single line for each category calculation per date and not a single date row for each date with multiple results on the same row.

2, How to implement the average, and running total columns?

I hope I have explained myself clearly. Confused | :confused: Unsure | :~

Any help is most appreciated.

Andy.

I don't speak Idiot - please talk slowly and clearly

modified on Monday, February 25, 2008 1:29 AM

GeneralRe: Query result not as expected Pin
GuyThiebaut24-Feb-08 11:18
professionalGuyThiebaut24-Feb-08 11:18 
GeneralRe: Query result not as expected Pin
Andy_L_J24-Feb-08 13:28
Andy_L_J24-Feb-08 13:28 
GeneralHelp with this select Pin
Caio Vitor23-Feb-08 5:25
Caio Vitor23-Feb-08 5:25 
GeneralRe: Help with this select Pin
Caio Vitor23-Feb-08 6:34
Caio Vitor23-Feb-08 6:34 
Generalsp_executesql Pin
SVb.net22-Feb-08 22:09
SVb.net22-Feb-08 22:09 
QuestionACCESS AND SQL HELP(A students question) Pin
ABQ4722-Feb-08 10:46
ABQ4722-Feb-08 10:46 
GeneralRe: ACCESS AND SQL HELP(A students question) Pin
pmarfleet22-Feb-08 10:58
pmarfleet22-Feb-08 10:58 
GeneralRe: ACCESS AND SQL HELP(A students question) Pin
Christian Graus22-Feb-08 11:15
protectorChristian Graus22-Feb-08 11:15 
GeneralRe: ACCESS AND SQL HELP(A students question) Pin
Paul Conrad25-Feb-08 8:51
professionalPaul Conrad25-Feb-08 8:51 
GeneralCombine 2 unrelated tables Pin
Lash2022-Feb-08 7:18
Lash2022-Feb-08 7:18 
GeneralRe: Combine 2 unrelated tables Pin
Lash2022-Feb-08 9:13
Lash2022-Feb-08 9:13 
GeneralRe: Combine 2 unrelated tables Pin
Mark J. Miller22-Feb-08 9:54
Mark J. Miller22-Feb-08 9:54 
GeneralCrystal Report with Ms SQL Server Pin
Member 367504722-Feb-08 0:58
Member 367504722-Feb-08 0:58 
GeneralAddress database schema Pin
pmpdesign21-Feb-08 15:44
pmpdesign21-Feb-08 15:44 
GeneralRe: Address database schema Pin
Christian Graus21-Feb-08 16:31
protectorChristian Graus21-Feb-08 16:31 
GeneralRe: Address database schema Pin
pmpdesign21-Feb-08 17:29
pmpdesign21-Feb-08 17:29 
GeneralRe: Address database schema Pin
Mark Churchill24-Feb-08 13:13
Mark Churchill24-Feb-08 13:13 

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.