Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL query error+SQL Server

Posted on 2014-07-31
6
Medium Priority
?
644 Views
Last Modified: 2014-08-07
Hi All,

Please suggest how to fix below error.

Error:
Msg 8117, Level 16, State 1, Procedure Employee_vw, Line 3
Operand data type bit is invalid for sum operator.
Msg 4413, Level 16, State 1, Line 8
Could not use view or function 'Employee_vw' because of binding errors.
select
concat(year,'-',(select left(datename(month,dateadd(month, month , -1)),3))) [Date],
sum(amount) [amount],
sum
(
[Met]
)
[Order] from Employee_vw
group by year,month
order by year,month

View structure:
Year	int
Month	int
[Met]	decimal
[amount]	int

Open in new window

0
Comment
Question by:sqldba2013
  • 3
  • 2
6 Comments
 
LVL 15

Accepted Solution

by:
Vikas Garg earned 750 total points
ID: 40233451
Hi,

have you used cross database reference in the View.

Since if it is a simple View then it will work perfectly as I have tested it locally and it is working fine..

CREATE VIEW [dbo].[Employee_VW]
AS
SELECT DISTINCT YEAR(FullDateAlternateKey) AS YEAR, MONTH(FullDateAlternateKey) AS MONTH, YEAR(FullDateAlternateKey) * 2 AS AMOUNT, MONTH(FullDateAlternateKey) * 2.5 AS MET
FROM            [AdventureWorksDW2012].[dbo].[DimDate]


GO

select
concat(year,'-',(select left(datename(month,dateadd(month, month , -1)),3))) [Date],
sum(amount) [amount],
sum
(
[Met]
)
[Order] from [dbo].[Employee_VW]
group by year,month
order by year,month

Open in new window

0
 

Author Comment

by:sqldba2013
ID: 40233460
Its simple view and still I am getting same error.
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 750 total points
ID: 40233505
assuming that MET is the bit field, you need to do:

SUM(cast(MET as int))
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

Author Comment

by:sqldba2013
ID: 40233508
Met data type is decimal not bit.

View structure:
Year      int
Month      int
[Met]      decimal
[amount]      int
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40233517
the issue is defintively then in the view Employee_vw, please post that full query

select concat(year,'-', left(datename(month,dateadd(month, month , -1)),3) ) [Date]
, sum(amount) [amount]
, sum([Met]) [Order] 
from Employee_vw
group by year,month
order by year,month

Open in new window

0
 

Author Closing Comment

by:sqldba2013
ID: 40245974
Thanks for your inputs. I have resolved my issue myself by modifying query.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question