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.
| Author |
Topic |
|
rob41
Yak Posting Veteran
67 Posts |
Posted - 2010-07-28 : 14:36:35
|
| I'm running this code and I'm getting the following errorConversion failed when converting the varchar value 'Sum of apr' to data type int.SELECT [Shipment].[load], [Shipment].[ship], SUM([Shipment].[estimate]) AS [est], SUM([Shipment].[approved]) AS [apr], [Shipment].[est acs] AS [Sum of est], [Shipment].[apr acs] AS [Sum of apr],CASE WHEN 'Sum of apr' = 0 OR 'Sum of apr' IS NULL THEN 'Sum of est' ELSE 'Sum of apr' END AS [other acs]INTO [other_acs47]FROM [Shipment]GROUP BY [load],[ship],[estimate],[approved]; |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2010-07-28 : 14:49:59
|
I'm not sure that's it...could beBUT[Shipment].[apr acs] AS [Sum of apr],CASE WHEN 'Sum of apr' = 0 You can't reference the label in the same select, I don't think (see, that always happens to me)You need to post the DDL for us to help youBrett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
rob41
Yak Posting Veteran
67 Posts |
Posted - 2010-07-28 : 14:52:16
|
| Tara, thanks it worked like a charm you rock!!!! |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2010-07-28 : 14:56:28
|
Well this is just flat out wrong..inconsistent grouping, ectSELECT [load] , [ship] , SUM([estimate]) AS [est] , SUM([approved]) AS [apr] , [est acs] AS [Sum of est] , [apr acs] AS [Sum of apr]......GROUP BY [load],[ship],[estimate],[approved]; What is this??? , [est acs] AS [Sum of est] , [apr acs] AS [Sum of apr]Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
|
|
|
|
|