Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Analysis Server and Reporting Services (2005)
 SQL Works in Svr Studio, not BI Studio-RESOLVED :(

Author  Topic 

JCirocco
Constraint Violating Yak Guru

392 Posts

Posted - 2009-09-28 : 15:35:38
I have a somewhat complex SQL select statement that has a number of normal joins but also has 5 derived tables with 5 different SUM calculated fields. When I created the statement on the SQL Server Management Studio console, it performs exactly as expected but when I copy and paste into the BI Visual Studio designer the calculated SUM fields display "Unsupported Data Type" when on the Data tab. If I flip to the Preview tab, all 5 calculated fields contain the correct value from the First field from the selects. That is, if Sum(Field1)=1, Sum(Field2)=2, Sum(Field3)=3, Sum(Field4)=4,Sum(Field5)=5
and the field order on the select statement resembles

Select Field4, Field2, Field5, Field3, Field1

The value for ALL 5 fields shows as "4" but if I flip Field4 and Field2 and make NO OTHER CHANGES:

Select Field2, Field4, Field5, Field3, Field1
The value for ALL 5 fields now shows as "2"

No-I am not crazy

What follows is the actual SQL but for me to create sample test data may not be practical. I bolded the lines but if it does not display that way to you, they aer the 5 qty fields after the select CASE statements.

 
SELECT ED_Contact.C_MemberNum AS [Member #],
ED_Contact.First_Name AS First,
ED_Contact.Last_Name AS Last,
ED_Contact.Address_1 AS Addr1,
ED_Contact.Address_2 AS Addr2,
ED_Contact.City,
ED_Contact.State_ AS State,
ED_Contact.Zip,
ED_Alt_Phone.Phone,
ED_Lead_.Phone AS [Other Phone],
ED_Lead_.C_Phone_Type AS [Other Phone Type],
ED_Alt_Phone_1.Email,
ED_Lead_.Email AS [Other Email],
ED_Lead_.C_Contact_Method AS [Pref. Ctct Method],
ED_Lead_.C_Time_To_Contact AS [Pref. Ctct Time],
ED_Lead_.C_Channel AS Channel,
ED_Lead_.Lead_Source_Type AS [Marketing Source],
ED_Contact_1.Rn_Descriptor AS [Ref. by Member],
ED_Employee.Rn_Descriptor AS [Ref. by Employee],
ED_C_Department.Rn_Descriptor AS [Ref. by Dept],
ED_Employee_1.Rn_Descriptor AS [Created By],
ED_C_Department_1.Rn_Descriptor AS [Create By Dept],
ED_Lead_.Rn_Create_Date AS [Created On],
ED_Lead_.C_Tr_Destination AS Destinations,
ED_Lead_.C_Tr_DepartureDate AS [Departure Date],
ED_Lead_.C_Tr_ReturnDate AS [Return Date],
ED_Lead_.C_Tr_TravelDateText AS [Travel Date Notes],
ED_Lead_.C_Tr_NumTravellers AS [Number Travelering],

CASE WHEN Interest_Cruise.[Cruise2] = 'Cruise'
THEN 'Yes'
ELSE ' '
END AS Cruise,

Interest_Cruise.[Cruise Qty] AS Qty,

CASE WHEN Interest_Motor_Coach.[Motor Coach2] = 'Motor Coach'
THEN 'Yes'
ELSE ' '
END AS [Motor Coach],

Interest_Motor_Coach.[Motor Coach Qty] AS Qty,

CASE WHEN Interest_Hotel.[Hotel2] = 'Hotel'
THEN 'Yes'
ELSE ' '
END AS Hotel,

Interest_Hotel.[Hotel Qty] AS Qty,

CASE WHEN Interest_Air.[Air2] = 'Air'
THEN 'Yes'
ELSE ' '
END AS Air,

Interest_Air.[Air Qty] AS Qty,

CASE WHEN Interest_Attraction_Tickets.[Attraction Tickets2] = 'Attraction Tickets'
THEN 'Yes'
ELSE ' '
END AS Tickets,

Interest_Attraction_Tickets.[Attraction Tickets Qty] AS Qty,

ED_Lead_.Comments

FROM ED_Lead_

INNER JOIN ED_Contact
ON ED_Lead_.Contact_Id = ED_Contact.Contact_Id

INNER JOIN ED_Employee AS ED_Employee_1
ON ED_Lead_.Created_By_Employee_Id = ED_Employee_1.Employee_Id

INNER JOIN ED_C_Lead_Type
ON ED_Lead_.C_Lead_Type_Id = ED_C_Lead_Type.C_Lead_Type_Id

LEFT OUTER JOIN ED_C_Department AS ED_C_Department_1
ON ED_Lead_.C_Create_User_Dept_Id = ED_C_Department_1.C_Department_Id

LEFT OUTER JOIN ED_C_Department
ON ED_Lead_.C_Refer_User_Dept_Id = ED_C_Department.C_Department_Id

LEFT OUTER JOIN ED_Employee
ON ED_Lead_.Referred_By_Employee_Id = ED_Employee.Employee_Id

LEFT OUTER JOIN ED_Contact AS ED_Contact_1
ON ED_Lead_.Referred_By_Contact_Id = ED_Contact_1.Contact_Id

LEFT OUTER JOIN ED_Alt_Phone AS ED_Alt_Phone_1
ON ED_Lead_.C_Email_Id = ED_Alt_Phone_1.Alt_Phone_Id

LEFT OUTER JOIN ED_Alt_Phone
ON ED_Lead_.C_Phone_Id = ED_Alt_Phone.Alt_Phone_Id

--- Cruise
LEFT OUTER JOIN
(SELECT Lead_Id,
Rn_Descriptor AS [Cruise2],
SUM(Quantity) AS [Cruise Qty]

FROM ED_Product_Interest AS Interest1
WHERE (Rn_Descriptor = 'Cruise')
GROUP BY Lead_Id,
Rn_Descriptor)
AS Interest_Cruise
ON ED_Lead_.Lead__Id = Interest_Cruise.Lead_Id

--- Motor Coach
LEFT OUTER JOIN
(SELECT Lead_Id,
Rn_Descriptor AS [Motor Coach2],
SUM(Quantity) AS [Motor Coach Qty]

FROM ED_Product_Interest AS Interest2
WHERE (Rn_Descriptor = 'Motor Coach')
GROUP BY Lead_Id,
Rn_Descriptor)
AS Interest_Motor_Coach
ON ED_Lead_.Lead__Id = Interest_Motor_Coach.Lead_Id

--- Hotel
LEFT OUTER JOIN
(SELECT Lead_Id,
Rn_Descriptor AS [Hotel2],
SUM(Quantity) AS [Hotel Qty]

FROM ED_Product_Interest AS Interest3
WHERE (Rn_Descriptor = 'Hotel')
GROUP BY Lead_Id,
Rn_Descriptor)
AS Interest_Hotel
ON ED_Lead_.Lead__Id = Interest_Hotel.Lead_Id

--- Air
LEFT OUTER JOIN
(SELECT Lead_Id,
Rn_Descriptor AS [Air2],
SUM(Quantity) AS [Air Qty]

FROM ED_Product_Interest AS Interest4
WHERE (Rn_Descriptor = 'Air')
GROUP BY Lead_Id,
Rn_Descriptor)
AS Interest_Air
ON ED_Lead_.Lead__Id = Interest_Air.Lead_Id

--- Attraction Tickets
LEFT OUTER JOIN
(SELECT Lead_Id,
Rn_Descriptor AS [Attraction Tickets2],
SUM(Quantity) AS [Attraction Tickets Qty]

FROM ED_Product_Interest AS Interest4
WHERE (Rn_Descriptor = 'Attraction Tickets')
GROUP BY Lead_Id,
Rn_Descriptor)
AS Interest_Attraction_Tickets
ON ED_Lead_.Lead__Id = Interest_Attraction_Tickets.Lead_Id

--- WHERE (ED_Lead_.Rn_Create_Date >= @StartDate) AND (ED_Lead_.Rn_Create_Date < @EndDate + 1)
WHERE (ED_Lead_.Rn_Create_Date >= getdate()-1) AND (ED_Lead_.Rn_Create_Date < getdate() + 1)
AND (ED_C_Lead_Type.Rn_Descriptor = 'Group Travel - Individual')



John

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-09-28 : 15:48:39
If it works fine in SSMS, then I'd suggest wrapping this beast into a stored procedure and then just executing the stored procedure in BIDS.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

JCirocco
Constraint Violating Yak Guru

392 Posts

Posted - 2009-09-28 : 20:41:54
Oh Mighty SQL Goddess (and YES I have many bookmarks to your blog at work...), I did try exactly that with the same results. That is one of the pieces that has us so baffled. I am going to try tomorrow to put some data creation statements together to see if it performs the same outside our vendors database. I have had 3 others looking into this last Friday and today and we are all scratching our head. I even forced a CAST of each to Int AND I also did things like:
(Interest_Cruise.[Cruise Qty]) * 1 AS Qty
and receive a result of ZERO.

Hopefully if I can find a way to recreate for everyone else, I can find out why I am going crazy this is happening.

John
Go to Top of Page

JCirocco
Constraint Violating Yak Guru

392 Posts

Posted - 2009-09-29 : 12:41:37
OK, I had someone I know walk up, took one look at the code and noted that all the fields BOLDED in the example all have the same Field Name on the "AS QTY". Well SQL Server is smart enough to figure it out but Reporting Services needs to have field names in the SQL match the field names in the RDL. I was assuming that the problem was in the derived tables. Quite a bit embarased by this one... Once that was resolved it also corrected the "Unsupported Data Type" I was getting on the Text fields. Chalking it up to lessons learned.

John
Go to Top of Page
   

- Advertisement -