Solved

SQL query error+SQL Server

Posted on 2014-07-31
6
618 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 250 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 142

Assisted Solution

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

SUM(cast(MET as int))
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

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 142

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

815 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now