Avatar of dev2dev
dev2devFlag for India

asked on 

Error while BCPing a views data (with Warning: Null value is eliminated by an aggregate or other SET operation)

Problem:
Unable to BCP a view

Error:
SQLState = 01003, NativeError = 8153
Warning = [Microsoft][ODBC SQL Server Driver][SQL Server]Warning: Null value is eliminated by an aggregate or other SET operation.

Why:
obviously that view giving aggregating some nulls

Solution Looking for:
Way to SET ANSI_WARNINGS OFF inside the view
or some other bcp switches
or some other settings
so that i wont get that warning and so that the bcp won't fail

Solutions not looking for:
Workarounds like, avoid getting those nulls using NOT NULL etc.,

Other info:

I checked db options "ansi warnings" is set to off

Background:

I have a view which has SUM aggregation on few columns
some times for some reason some of these columns gets NULL and for obvious reason SQL server gives a warning message "Warning: Null value is eliminated by an aggregate or other SET operation."

i checked db properties and found ansi_warnings is set OFF

i cross checked using this query as well

select name,is_ansi_warnings_on from sys.databases

which is showing 0 (meaning OFF? correct if am wrong)

use a dummy view i created to simulate the issue

thanks for your help in advance
-- Create this view to simulate the issue
CREATE VIEW VW_DUMMY 
AS
SELECT * FROM (
SELECT SUM(CAST(NULL AS INT)) AS SOME_FILED )AS X WHERE SOME_FILED IS NOT NULL
go
 
-- and bcp using below command-line
 
bcp mydbname..vw_dummy out dummy.txt -Smyservername -T -c
 
SET ANSI_WARNINGS ON
select * from vw_dummy -- switch to messages tab, shows a warnig message
SET ANSI_WARNINGS OFF
select * from vw_dummy -- now it wont

Open in new window

Microsoft SQL Server 2005

Avatar of undefined
Last Comment
dev2dev
Avatar of momi_sabag
momi_sabag
Flag of United States of America image

hi
since the only aggreagate function you use is SUM, i think the simplest solution will be to change you query to
SELECT * FROM (
SELECT SUM(ISNULL(your_column,0)) AS SOME_FILED )AS X WHERE SOME_FILED IS NOT NULL
go


since adding 0 to the sum does not change the result
Avatar of dev2dev
dev2dev
Flag of India image

ASKER

thanks for reply
that option is always available
unfortunately i cannot do it, because 0s have different meaning in our product

any way i was looking for the solution

how to suppress that warning message without having me to do all those null handling

just like set ansi_warnings off in active.connections/sps
ASKER CERTIFIED SOLUTION
Avatar of momi_sabag
momi_sabag
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of dev2dev
dev2dev
Flag of India image

ASKER

I mentioned in my first post.

Solution Looking for:
Way to SET ANSI_WARNINGS OFF inside the view
or some other bcp switches
or some other settings
so that i wont get that warning and so that the bcp won't fail

Solutions not looking for:
Workarounds like, avoid getting those nulls using NOT NULL etc.,
====

momi_sabag's answer is alternate which was always there. any way, I don't mind if you give points for trying to help out
Microsoft SQL Server 2005
Microsoft SQL Server 2005

Microsoft SQL Server 2005 is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning. It includes support for managing XML data and allows a database server to be exposed over web services using Tabular Data Stream (TDS) packets encapsulated within SOAP (protocol) requests.

72K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo