Click here to Skip to main content
15,888,521 members
Home / Discussions / Database
   

Database

 
AnswerRe: string truncation Pin
PIEBALDconsult9-Nov-11 15:28
mvePIEBALDconsult9-Nov-11 15:28 
AnswerRe: string truncation Pin
Wayne Gaylard9-Nov-11 17:09
professionalWayne Gaylard9-Nov-11 17:09 
AnswerRe: string truncation Pin
Luc Pattyn9-Nov-11 17:28
sitebuilderLuc Pattyn9-Nov-11 17:28 
GeneralRe: string truncation Pin
Wayne Gaylard9-Nov-11 17:42
professionalWayne Gaylard9-Nov-11 17:42 
GeneralRe: string truncation Pin
Luc Pattyn9-Nov-11 17:48
sitebuilderLuc Pattyn9-Nov-11 17:48 
GeneralRe: string truncation Pin
Mycroft Holmes13-Nov-11 6:13
professionalMycroft Holmes13-Nov-11 6:13 
GeneralRe: string truncation Pin
Luc Pattyn13-Nov-11 6:35
sitebuilderLuc Pattyn13-Nov-11 6:35 
QuestionTrying to get Pivot Table working in MS SQL 2005 Pin
VREntropy9-Nov-11 8:56
VREntropy9-Nov-11 8:56 
I have never used a pivot before and I am starting to think that one doesnt work. Please help provide guidence.



I have 3 tables

_Contracts, which contain contractid and sepworkstatus

_contracts
--------------------
1,[Sent]
2,[Sent]
3,[No Further Action]


_vendors which has umbrellaname and vendornumber _contracts.vendorid is foreign to _vendors.vendornumber

_vendors
---------------------
um1,1
um2,2
um2,3


and _UmbrellaData which has umbrellaname and a few other needless columns. umbrellaname connects _UmbrellaData and _vendors

_UmbrellaData
---------------------
um1
um2

The outer apply will grab a list of all the statuses and their counts for each umbrella company

The results will look similar to

um1,sent,1
um2,No Further Action, 1
um2,sent,1
um3,Executed

my output needs to look like this

umbrellaname, sent, [No Further Action], [Executed]
um1,1,null,null
um2,1,1,null

My current query looks like this

select
u.umbrellaname, u.stream, functionalarea,
[In Negotiation],[Prework Complete],[Sent],[No Further Action],[Executed],[Separation Work Started],[Ready to Send],[Prework Started]
from dbo._UmbrellaData u
outer apply (
select v.umbrellaname, c.sepworkstatus, count(c.sepworkstatus) as counte from dbo._Vendor v
join dbo._Contracts c on c.vendorid = v.vendornumber
group by v.umbrellaname, c.sepworkstatus
) as oa
pivot(max(oa.counte) for oa.sepworkstatus in (
[In Negotiation],[Prework Complete],[Sent],[No Further Action],[Executed],[Separation Work Started],[Ready to Send],[Prework Started]
)) as cw
where oa.umbrellaname = u.umbrellaname





Unfortunately when I run it I get the following errors.



Msg 8156, Level 16, State 1, Line 2
The column 'umbrellaname' was specified multiple times for 'cw'.
Msg 4104, Level 16, State 1, Line 2
The multi-part identifier "oa.umbrellaname" could not be bound.
Msg 4104, Level 16, State 1, Line 2
The multi-part identifier "u.umbrellaname" could not be bound.
Msg 4104, Level 16, State 1, Line 2
The multi-part identifier "u.umbrellaname" could not be bound.
Msg 4104, Level 16, State 1, Line 2
The multi-part identifier "u.stream" could not be bound.



Why? How do I get a pivot to work with an outer apply?



Any help on this would be greatly appreciated.
AnswerRe: Trying to get Pivot Table working in MS SQL 2005 Pin
Mycroft Holmes13-Nov-11 6:06
professionalMycroft Holmes13-Nov-11 6:06 
GeneralRe: Trying to get Pivot Table working in MS SQL 2005 Pin
VREntropy14-Nov-11 3:13
VREntropy14-Nov-11 3:13 
Questionhow to avoid this error? Pin
Jassim Rahma9-Nov-11 5:22
Jassim Rahma9-Nov-11 5:22 
AnswerRe: how to avoid this error? Pin
loyal ginger9-Nov-11 5:41
loyal ginger9-Nov-11 5:41 
AnswerRe: how to avoid this error? Pin
jschell9-Nov-11 11:25
jschell9-Nov-11 11:25 
QuestionCannot connect a remote SQL server 2005... Pin
Jun Du9-Nov-11 3:35
Jun Du9-Nov-11 3:35 
AnswerRe: Cannot connect a remote SQL server 2005... Pin
Luc Pattyn9-Nov-11 4:01
sitebuilderLuc Pattyn9-Nov-11 4:01 
GeneralRe: Cannot connect a remote SQL server 2005... Pin
Jun Du9-Nov-11 4:49
Jun Du9-Nov-11 4:49 
AnswerRe: Cannot connect a remote SQL server 2005... Pin
Luc Pattyn9-Nov-11 4:54
sitebuilderLuc Pattyn9-Nov-11 4:54 
GeneralRe: Cannot connect a remote SQL server 2005... Pin
Jun Du9-Nov-11 5:09
Jun Du9-Nov-11 5:09 
QuestionMS SQL Server Trigger help Pin
eddjusted9-Nov-11 3:18
eddjusted9-Nov-11 3:18 
AnswerRe: MS SQL Server Trigger help Pin
R. Giskard Reventlov9-Nov-11 3:49
R. Giskard Reventlov9-Nov-11 3:49 
GeneralRe: MS SQL Server Trigger help Pin
eddjusted9-Nov-11 3:56
eddjusted9-Nov-11 3:56 
AnswerRe: MS SQL Server Trigger help Pin
Corporal Agarn9-Nov-11 6:26
professionalCorporal Agarn9-Nov-11 6:26 
QuestionMySQL query help Pin
eddjusted9-Nov-11 3:02
eddjusted9-Nov-11 3:02 
AnswerRe: MySQL query help Pin
Blue_Boy9-Nov-11 3:18
Blue_Boy9-Nov-11 3:18 
GeneralRe: MySQL query help Pin
eddjusted9-Nov-11 3:20
eddjusted9-Nov-11 3:20 

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.