Sunday, March 25, 2012
Do I need more integrity on my DB?
thanks
************************************************** *****
create table person(
personId int identity(1,1) primary key,
fName varchar(25) not null,
mI char(1) null,
lName varchar(25) not null
);
create table student(
studentId char(4) not null primary key,
personId int not null
);
alter table student
add constraint fk_person_student
foreign key (personId)
references person (personId)
;
create table instructor(
instructorId char(4) not null primary key,
instructorQual varchar(100) not null,
personId int not null
);
alter table instructor
add constraint fk_person_instructor
foreign key (personId)
references person (personId)
;
create table contract(
contractNum int identity(1,1) primary key,
contractDate smalldatetime not null,
tuition money not null,
studentId char(4) not null foreign key references student (studentId),
contactId int not null foreign key references contact (contactId)
);
create table contact(
contactId int not null primary key,
fName varchar(25) not null,
mI char(1) null,
lName varchar(25) not null,
street varchar(50) not null,
city varchar(25) not null,
state char(2) not null,
zip char(5) not null,
relationship varchar(25) not null,
phNum char(12) not null,
emailAdd varchar(50) null,
);
create table class(
classNum char(4) not null primary key,
className varchar(25) not null,
classDay char(3) not null,
classTime char(8) not null,
testNum char(5) not null
);
alter table class
add constraint fk_class_testnum
foreign key (testNum)
references test (testNum)
;
create table discount(
discountNum char(3) primary key,
discountDesc varchar(100) not null,
discountPer decimal(3,2) not null
);
create table test(
testNum char(5) primary key,
testName varchar(50) not null,
testDate smalldatetime not null,
testFee money not null,
);
create table studentClass(
studentId char(4) not null,
classNum char(4) not null,
pass char(1) not null
);
alter table studentClass
add constraint pk_studentclass primary key clustered (studentId, classNum)
;
alter table studentClass
add constraint fk_studentclass_studenttid
foreign key (studentId)
references student(studentId)
;
alter table studentClass
add constraint fk_studentclass_classnum
foreign key (classNum)
references class(classNum)
;
create table contractDiscount(
contractNum int not null,
discountNum char(3) not null
);
alter table contractDiscount
add constraint pk_contractdiscount primary key clustered (contractNum, discountNum)
;
alter table contractDiscount
add constraint fk_contractdiscount_contractnum
foreign key (contractNum)
references contract(contractNum)
;
alter table contractDiscount
add constraint fk_contractdiscount_discountnum
foreign key (discountNum)
references discount(discountNum)
;
create table instructorClass(
instructorId char(4) not null,
classNum char(4) not null,
);
alter table instructorClass
add constraint pk_instructorclass primary key clustered (instructorId, classNum)
;
alter table instructorClass
add constraint fk_instructorclass_instructorid
foreign key (instructorId)
references instructor(instructorId)
;
alter table instructorClass
add constraint fk_instructorclass_classnum
foreign key (classnum)
references class(classnum)
;Without knowing more about your business and the applications using the database, it's very hard to say if you need more. It's possible. This looks good though just from looking at it.|||as a specific example.
I have a contract table which is connected to student, contact and contractDiscount table with studentId and contactId as a FK. contractDiscount table is a intersection table.
IF I try to delete a contract record it won't let me, unlease I delete the discount relation on contractDiscount table. when I delete the relation with that certain row in discount on contractDiscount table then I am able to delete the contract.
However in that case, my student table and contact table record will be there without the existing contract.
My first question is do i even need to delete those records in student and contact table for intefrity of DB, when I delete the contract table?
second question is If I need to delete the record how I do that because without deleting contractDiscout record, I am not even able to delete the contract record.
Wednesday, March 21, 2012
DNS-less connection w/ no prompt VB
I can connect using the below connection string ...
Driver={SQL
Server};SERVER=MYSERVER;UID=MYUSERNAME;PWD=myPASSWORD;DATABASE=myDATABASE;
WHEN I USE...
Set dbsODBC = OpenDatabase("",False, False, strConnect)
BUT IF I try to disable the prompt using...
Set dbsODBC = OpenDatabase("", dbDriverNoPrompt, False, strConnect)
AND
Set dbsODBC = OpenDatabase("", dbDriverNoPrompt, False,"ODBC;" &
strConnect)
my connection either does not connect or it displays the prompt. I
think the problem has something to do with me not using a DSN, but I
thought I should be able to connect without one. PLEASE HELP!
What am I doing wrong, and why would this be happening?
THANK YOU!!I don't understand your question. Open Database is a method of the Jet
database engine (DAO) used with Microsoft Access, not SQL Server. The
connection string you are using is not the correct syntax for the DAO
OpenDatabase method. If you're trying to open an Access database that has a
table in it that is linked to SQL Server, then the linked table has to have
the DSN-less connection string in it's Connect property and you need to use
the syntax for DAO as the parameter to the OpenDatabase function. But, I'm
having a hard time figuring out why you would want to do this? To connect to
a SQL Server DB from VB you should be using ADO (ActiveX Data Objects). The
connection string you are using *is* the correct syntax for the ADO
Connection object's Open method. No need for Jet or Access at this point.
<stoppal@.hotmail.com> wrote in message
news:1129838783.819043.87440@.o13g2000cwo.googlegroups.com...
> I have a problem trying to link my access table using VB
>
> I can connect using the below connection string ...
>
> Driver={SQL
> Server};SERVER=MYSERVER;UID=MYUSERNAME;PWD=myPASSWORD;DATABASE=myDATABASE;
>
> WHEN I USE...
>
> Set dbsODBC = OpenDatabase("",False, False, strConnect)
>
> BUT IF I try to disable the prompt using...
>
> Set dbsODBC = OpenDatabase("", dbDriverNoPrompt, False, strConnect)
> AND
> Set dbsODBC = OpenDatabase("", dbDriverNoPrompt, False,"ODBC;" &
> strConnect)
>
> my connection either does not connect or it displays the prompt. I
> think the problem has something to do with me not using a DSN, but I
> thought I should be able to connect without one. PLEASE HELP!
>
> What am I doing wrong, and why would this be happening?
>
> THANK YOU!!
>|||thank you for the recommendation I'll try it at work tommorrow.
I'll tell you if it works friday, morning|||GOT IT WORKS, THANK YOU!!!!!!!!!!!!!!!!
DNS-less connection w/ no prompt VB
I can connect using the below connection string ...
Driver={SQL
Server};SERVER=MYSERVER;UID=MYUSERNAME;P
WD=myPASSWORD;DATABASE=myDATABASE;
WHEN I USE...
Set dbsODBC = OpenDatabase("",False, False, strConnect)
BUT IF I try to disable the prompt using...
Set dbsODBC = OpenDatabase("", dbDriverNoPrompt, False, strConnect)
AND
Set dbsODBC = OpenDatabase("", dbDriverNoPrompt, False,"ODBC;" &
strConnect)
my connection either does not connect or it displays the prompt. I
think the problem has something to do with me not using a DSN, but I
thought I should be able to connect without one. PLEASE HELP!
What am I doing wrong, and why would this be happening?
THANK YOU!!I don't understand your question. Open Database is a method of the Jet
database engine (DAO) used with Microsoft Access, not SQL Server. The
connection string you are using is not the correct syntax for the DAO
OpenDatabase method. If you're trying to open an Access database that has a
table in it that is linked to SQL Server, then the linked table has to have
the DSN-less connection string in it's Connect property and you need to use
the syntax for DAO as the parameter to the OpenDatabase function. But, I'm
having a hard time figuring out why you would want to do this? To connect to
a SQL Server DB from VB you should be using ADO (ActiveX Data Objects). The
connection string you are using *is* the correct syntax for the ADO
Connection object's Open method. No need for Jet or Access at this point.
<stoppal@.hotmail.com> wrote in message
news:1129838783.819043.87440@.o13g2000cwo.googlegroups.com...
> I have a problem trying to link my access table using VB
>
> I can connect using the below connection string ...
>
> Driver={SQL
> Server};SERVER=MYSERVER;UID=MYUSERNAME;P
WD=myPASSWORD;DATABASE=myDATABASE;
>
> WHEN I USE...
>
> Set dbsODBC = OpenDatabase("",False, False, strConnect)
>
> BUT IF I try to disable the prompt using...
>
> Set dbsODBC = OpenDatabase("", dbDriverNoPrompt, False, strConnect)
> AND
> Set dbsODBC = OpenDatabase("", dbDriverNoPrompt, False,"ODBC;" &
> strConnect)
>
> my connection either does not connect or it displays the prompt. I
> think the problem has something to do with me not using a DSN, but I
> thought I should be able to connect without one. PLEASE HELP!
>
> What am I doing wrong, and why would this be happening?
>
> THANK YOU!!
>|||thank you for the recommendation I'll try it at work tommorrow.
I'll tell you if it works friday, morning|||GOT IT WORKS, THANK YOU!!!!!!!!!!!!!!!!
DNS-less connection w/ no prompt VB
I can connect using the below connection string ...
Driver={SQL
Server};SERVER=MYSERVER;UID=MYUSERNAME;PWD=myPASSW ORD;DATABASE=myDATABASE;
WHEN I USE...
Set dbsODBC = OpenDatabase("",False, False, strConnect)
BUT IF I try to disable the prompt using...
Set dbsODBC = OpenDatabase("", dbDriverNoPrompt, False, strConnect)
AND
Set dbsODBC = OpenDatabase("", dbDriverNoPrompt, False,"ODBC;" &
strConnect)
my connection either does not connect or it displays the prompt. I
think the problem has something to do with me not using a DSN, but I
thought I should be able to connect without one. PLEASE HELP!
What am I doing wrong, and why would this be happening?
THANK YOU!!
I don't understand your question. Open Database is a method of the Jet
database engine (DAO) used with Microsoft Access, not SQL Server. The
connection string you are using is not the correct syntax for the DAO
OpenDatabase method. If you're trying to open an Access database that has a
table in it that is linked to SQL Server, then the linked table has to have
the DSN-less connection string in it's Connect property and you need to use
the syntax for DAO as the parameter to the OpenDatabase function. But, I'm
having a hard time figuring out why you would want to do this? To connect to
a SQL Server DB from VB you should be using ADO (ActiveX Data Objects). The
connection string you are using *is* the correct syntax for the ADO
Connection object's Open method. No need for Jet or Access at this point.
<stoppal@.hotmail.com> wrote in message
news:1129838783.819043.87440@.o13g2000cwo.googlegro ups.com...
> I have a problem trying to link my access table using VB
>
> I can connect using the below connection string ...
>
> Driver={SQL
> Server};SERVER=MYSERVER;UID=MYUSERNAME;PWD=myPASSW ORD;DATABASE=myDATABASE;
>
> WHEN I USE...
>
> Set dbsODBC = OpenDatabase("",False, False, strConnect)
>
> BUT IF I try to disable the prompt using...
>
> Set dbsODBC = OpenDatabase("", dbDriverNoPrompt, False, strConnect)
> AND
> Set dbsODBC = OpenDatabase("", dbDriverNoPrompt, False,"ODBC;" &
> strConnect)
>
> my connection either does not connect or it displays the prompt. I
> think the problem has something to do with me not using a DSN, but I
> thought I should be able to connect without one. PLEASE HELP!
>
> What am I doing wrong, and why would this be happening?
>
> THANK YOU!!
>
|||thank you for the recommendation I'll try it at work tommorrow.
I'll tell you if it works friday, morning
|||GOT IT WORKS, THANK YOU!!!!!!!!!!!!!!!!
Monday, March 19, 2012
DMO doesn't work with SQL Server 2005 (Express)?
When I tried to run that app against SQL Server 2005 Express CTP,
I got the below error:
Error
[Microsoft][ODBC SQL Server Driver][SQL Server]
To connect to this server you must use SQL Server Management Studio or SQL Server Management Objects (SMO)
OK
Any idea what I'm missing here?
Thanks,
Sarah
DMO is not supported on SQL2005. You need to use SMO.
Chris Wood
"Sarah" <SarahBram@.HotMail.com> wrote in message
news:%23xZE7FzrFHA.904@.tk2msftngp13.phx.gbl...
>I have an applications that uses DMO to access SQL Server 2000.
> When I tried to run that app against SQL Server 2005 Express CTP,
> I got the below error:
> --
> Error
> --
> [Microsoft][ODBC SQL Server Driver][SQL Server]
> To connect to this server you must use SQL Server Management Studio or SQL
> Server Management Objects (SMO)
> --
> OK
> --
> Any idea what I'm missing here?
> Thanks,
> Sarah
|||Hello Chris,
If I complie in SMO will it be backward compatible with SQL 2000 or do I
need to include both in my applications?
Regards,
John
"Chris Wood" <anonymous@.discussions.microsoft.com> wrote in message
news:OZiB6lzrFHA.248@.TK2MSFTNGP14.phx.gbl...
> DMO is not supported on SQL2005. You need to use SMO.
> Chris Wood
> "Sarah" <SarahBram@.HotMail.com> wrote in message
> news:%23xZE7FzrFHA.904@.tk2msftngp13.phx.gbl...
>
|||Chris Wood wrote:
> DMO is not supported on SQL2005. You need to use SMO.
> Chris Wood
Chris,
There is a SQL Server DMO in Beta now for SQL Server 2005. I'm guessing
Microsoft decided they didn't want to make upgrading DMO apps any more
difficult than they needed to be. The new SQL-DMO is supposed to work
with SQL 2000 and 7. I'm not sure when it will be available for
download if you're not a beta member.
David Gugick
Quest Software
www.imceda.com
www.quest.com
|||David,
Hopefully the new version of DMO comes with the September CTP and before the
RTM (Gold) build.
Thanks
Chris
"David Gugick" <david.gugick-nospam@.quest.com> wrote in message
news:Om36c$zrFHA.3596@.TK2MSFTNGP15.phx.gbl...
> Chris Wood wrote:
> Chris,
> There is a SQL Server DMO in Beta now for SQL Server 2005. I'm guessing
> Microsoft decided they didn't want to make upgrading DMO apps any more
> difficult than they needed to be. The new SQL-DMO is supposed to work with
> SQL 2000 and 7. I'm not sure when it will be available for download if
> you're not a beta member.
>
> --
> David Gugick
> Quest Software
> www.imceda.com
> www.quest.com
|||David,
Did this make it with the September CTP?
Chris
"David Gugick" <david.gugick-nospam@.quest.com> wrote in message
news:Om36c$zrFHA.3596@.TK2MSFTNGP15.phx.gbl...
> Chris Wood wrote:
> Chris,
> There is a SQL Server DMO in Beta now for SQL Server 2005. I'm guessing
> Microsoft decided they didn't want to make upgrading DMO apps any more
> difficult than they needed to be. The new SQL-DMO is supposed to work with
> SQL 2000 and 7. I'm not sure when it will be available for download if
> you're not a beta member.
>
> --
> David Gugick
> Quest Software
> www.imceda.com
> www.quest.com
DMO doesn't work with SQL Server 2005 (Express)?
When I tried to run that app against SQL Server 2005 Express CTP,
I got the below error:
--
Error
--
[Microsoft][ODBC SQL Server Driver][SQL Server]
To connect to this server you must use SQL Server Management Studio or SQL Server Management Objects (SMO)
--
OK
--
Any idea what I'm missing here?
Thanks,
SarahDMO is not supported on SQL2005. You need to use SMO.
Chris Wood
"Sarah" <SarahBram@.HotMail.com> wrote in message
news:%23xZE7FzrFHA.904@.tk2msftngp13.phx.gbl...
>I have an applications that uses DMO to access SQL Server 2000.
> When I tried to run that app against SQL Server 2005 Express CTP,
> I got the below error:
> --
> Error
> --
> [Microsoft][ODBC SQL Server Driver][SQL Server]
> To connect to this server you must use SQL Server Management Studio or SQL
> Server Management Objects (SMO)
> --
> OK
> --
> Any idea what I'm missing here?
> Thanks,
> Sarah|||Hello Chris,
If I complie in SMO will it be backward compatible with SQL 2000 or do I
need to include both in my applications?
Regards,
John
"Chris Wood" <anonymous@.discussions.microsoft.com> wrote in message
news:OZiB6lzrFHA.248@.TK2MSFTNGP14.phx.gbl...
> DMO is not supported on SQL2005. You need to use SMO.
> Chris Wood
> "Sarah" <SarahBram@.HotMail.com> wrote in message
> news:%23xZE7FzrFHA.904@.tk2msftngp13.phx.gbl...
>>I have an applications that uses DMO to access SQL Server 2000.
>> When I tried to run that app against SQL Server 2005 Express CTP,
>> I got the below error:
>> --
>> Error
>> --
>> [Microsoft][ODBC SQL Server Driver][SQL Server]
>> To connect to this server you must use SQL Server Management Studio or
>> SQL Server Management Objects (SMO)
>> --
>> OK
>> --
>> Any idea what I'm missing here?
>> Thanks,
>> Sarah
>|||Chris Wood wrote:
> DMO is not supported on SQL2005. You need to use SMO.
> Chris Wood
Chris,
There is a SQL Server DMO in Beta now for SQL Server 2005. I'm guessing
Microsoft decided they didn't want to make upgrading DMO apps any more
difficult than they needed to be. The new SQL-DMO is supposed to work
with SQL 2000 and 7. I'm not sure when it will be available for
download if you're not a beta member.
David Gugick
Quest Software
www.imceda.com
www.quest.com|||David,
Hopefully the new version of DMO comes with the September CTP and before the
RTM (Gold) build.
Thanks
Chris
"David Gugick" <david.gugick-nospam@.quest.com> wrote in message
news:Om36c$zrFHA.3596@.TK2MSFTNGP15.phx.gbl...
> Chris Wood wrote:
>> DMO is not supported on SQL2005. You need to use SMO.
>> Chris Wood
> Chris,
> There is a SQL Server DMO in Beta now for SQL Server 2005. I'm guessing
> Microsoft decided they didn't want to make upgrading DMO apps any more
> difficult than they needed to be. The new SQL-DMO is supposed to work with
> SQL 2000 and 7. I'm not sure when it will be available for download if
> you're not a beta member.
>
> --
> David Gugick
> Quest Software
> www.imceda.com
> www.quest.com|||David,
Did this make it with the September CTP?
Chris
"David Gugick" <david.gugick-nospam@.quest.com> wrote in message
news:Om36c$zrFHA.3596@.TK2MSFTNGP15.phx.gbl...
> Chris Wood wrote:
>> DMO is not supported on SQL2005. You need to use SMO.
>> Chris Wood
> Chris,
> There is a SQL Server DMO in Beta now for SQL Server 2005. I'm guessing
> Microsoft decided they didn't want to make upgrading DMO apps any more
> difficult than they needed to be. The new SQL-DMO is supposed to work with
> SQL 2000 and 7. I'm not sure when it will be available for download if
> you're not a beta member.
>
> --
> David Gugick
> Quest Software
> www.imceda.com
> www.quest.com
DMO doesn't work with SQL Server 2005 (Express)?
When I tried to run that app against SQL Server 2005 Express CTP,
I got the below error:
Error
--
[Microsoft][ODBC SQL Server Driver][SQL Server]
To connect to this server you must use SQL Server Management Studio or SQL S
erver Management Objects (SMO)
--
OK
--
Any idea what I'm missing here?
Thanks,
SarahDMO is not supported on SQL2005. You need to use SMO.
Chris Wood
"Sarah" <SarahBram@.HotMail.com> wrote in message
news:%23xZE7FzrFHA.904@.tk2msftngp13.phx.gbl...
>I have an applications that uses DMO to access SQL Server 2000.
> When I tried to run that app against SQL Server 2005 Express CTP,
> I got the below error:
> --
> Error
> --
> [Microsoft][ODBC SQL Server Driver][SQL Server]
> To connect to this server you must use SQL Server Management Studio or SQL
> Server Management Objects (SMO)
> --
> OK
> --
> Any idea what I'm missing here?
> Thanks,
> Sarah|||Hello Chris,
If I complie in SMO will it be backward compatible with SQL 2000 or do I
need to include both in my applications?
Regards,
John
"Chris Wood" <anonymous@.discussions.microsoft.com> wrote in message
news:OZiB6lzrFHA.248@.TK2MSFTNGP14.phx.gbl...
> DMO is not supported on SQL2005. You need to use SMO.
> Chris Wood
> "Sarah" <SarahBram@.HotMail.com> wrote in message
> news:%23xZE7FzrFHA.904@.tk2msftngp13.phx.gbl...
>|||Chris Wood wrote:
> DMO is not supported on SQL2005. You need to use SMO.
> Chris Wood
Chris,
There is a SQL Server DMO in Beta now for SQL Server 2005. I'm guessing
Microsoft decided they didn't want to make upgrading DMO apps any more
difficult than they needed to be. The new SQL-DMO is supposed to work
with SQL 2000 and 7. I'm not sure when it will be available for
download if you're not a beta member.
David Gugick
Quest Software
www.imceda.com
www.quest.com|||David,
Hopefully the new version of DMO comes with the September CTP and before the
RTM (Gold) build.
Thanks
Chris
"David Gugick" <david.gugick-nospam@.quest.com> wrote in message
news:Om36c$zrFHA.3596@.TK2MSFTNGP15.phx.gbl...
> Chris Wood wrote:
> Chris,
> There is a SQL Server DMO in Beta now for SQL Server 2005. I'm guessing
> Microsoft decided they didn't want to make upgrading DMO apps any more
> difficult than they needed to be. The new SQL-DMO is supposed to work with
> SQL 2000 and 7. I'm not sure when it will be available for download if
> you're not a beta member.
>
> --
> David Gugick
> Quest Software
> www.imceda.com
> www.quest.com|||David,
Did this make it with the September CTP?
Chris
"David Gugick" <david.gugick-nospam@.quest.com> wrote in message
news:Om36c$zrFHA.3596@.TK2MSFTNGP15.phx.gbl...
> Chris Wood wrote:
> Chris,
> There is a SQL Server DMO in Beta now for SQL Server 2005. I'm guessing
> Microsoft decided they didn't want to make upgrading DMO apps any more
> difficult than they needed to be. The new SQL-DMO is supposed to work with
> SQL 2000 and 7. I'm not sure when it will be available for download if
> you're not a beta member.
>
> --
> David Gugick
> Quest Software
> www.imceda.com
> www.quest.com
DMI Indication
i am getting error. i dont understand what is this error
can any one help me out & tell us why this error is coming
here i am attaching the below error for Ref..
DMI Indication
Event Type = Cable unplugged/No LAN activity
Component Name = Intel Ethernet LAN Adapter(s)
Group = NIC Health Contributor
Severity = Information
Instance = Not Applicable
System = Unknown
SubSystem = DriverI don't believe that this message is in any way related to SQL Server.
Please try other newsgroups dealing with networking issues for this
question.
Thank you for using Microsoft newsgroups.
Sincerely
Pankaj Agarwal
Microsoft Corporation
This posting is provided AS IS with no warranties, and confers no rights.
DMI Indication
i am getting error. i dont understand what is this error
can any one help me out & tell us why this error is coming
here i am attaching the below error for Ref..
DMI Indication
Event Type = Cable unplugged/No LAN activity
Component Name = Intel Ethernet LAN Adapter(s)
Group = NIC Health Contributor
Severity = Information
Instance = Not Applicable
System = Unknown
SubSystem = DriverI don't believe that this message is in any way related to SQL Server.
Please try other newsgroups dealing with networking issues for this
question.
Thank you for using Microsoft newsgroups.
Sincerely
Pankaj Agarwal
Microsoft Corporation
This posting is provided AS IS with no warranties, and confers no rights.
DMI Indication
i am getting error. i dont understand what is this error
can any one help me out & tell us why this error is coming
here i am attaching the below error for Ref..
DMI Indication
Event Type= Cable unplugged/No LAN activity
Component Name= Intel Ethernet LAN Adapter(s)
Group= NIC Health Contributor
Severity= Information
Instance= Not Applicable
System= Unknown
SubSystem= Driver
I don't believe that this message is in any way related to SQL Server.
Please try other newsgroups dealing with networking issues for this
question.
Thank you for using Microsoft newsgroups.
Sincerely
Pankaj Agarwal
Microsoft Corporation
This posting is provided AS IS with no warranties, and confers no rights.
Sunday, March 11, 2012
dm query taking long time
I'm running a query (see below) on my development server and its taking around 45 seconds. It hosts 18 user databases ranging from 3 MB to 400 MB. The production server, which is very similar but with only 1 25 MB user database, runs the query in less than 1 second. Both servers have been running on VMWare for almost 1 year with no problems. However last week I applied SP 2 to the development server, and yesterday I applied Critical Update KB934458. The production server is still running SQL Server 2005 Standard SP 1. Other than that, both servers are identical and running Windows 2003 Server Standard SP 1. I'm not seeing this discrepancy with other queries running against user databases.
use MyDatabase
GO
select db_name(database_id) as 'Database', o.name as 'Table',
s.index_id, index_type_desc, alloc_unit_type_desc, index_level, i.name as 'Index Name',
avg_fragmentation_in_percent, fragment_count, avg_fragment_size_in_pages,
page_count, avg_page_space_used_in_percent, record_count,
ghost_record_count, min_record_size_in_bytes, avg_record_size_in_bytes, forwarded_record_count,
schema_id, create_date, modify_date from sys.dm_db_index_physical_stats (null, null, null, null, 'DETAILED') s
join sys.objects o on s.object_id = o.object_id
join sys.indexes i on i.object_id = s.object_id and i.index_id = s.index_id
where db_name(database_id) = 'MyDatabase'
order by avg_fragmentation_in_percent desc
--order by avg_fragment_size_in_pages desc
--order by page_count desc
--order by record_count desc
--order by avg_record_size_in_bytes desc
Alright Chap check this out.
Your dev server has 18 user databases and the
sys.dm_db_index_physical_stats (null, null, null, null, 'DETAILED')
checks all the databases.
replace the first NULL with the DBID of the database mydatabase and try running it again.
Jag
|||Thanks. So, I can consider this to be normal behavior?I reduced the number of user databases from 18 to 9. Now it runs in about 1 second. (Same query, I haven't yet made the change you suggested.) I think its safe to say that this query does not scale!
|||In 'DETAILED mode the dmv will read all pages that are used in a database. In the query that you specified, you indicated that you wanted to walk though all the pages in all the databases that were available on the system. If you have one big database with a lot of data, this command will take a long time because of all the I/O.
If you want faster (but less detailed) results, you can use 'LIMITED' mode.
Thanks,
Division by Zero Error
SELECT FromDate AS MonthOneDate,State,Description,SUM(Flowthru) AS CELCSumFT,SUM(TotalCount) AS CELCsumCNT,
(SUM(Flowthru)/SUM(TotalCount)) * 100 AS CELCFtPct,
RetailNum AS ARZSumFT,RetailDen AS
ARZSumCnt,(RetailNum/RetailDen) * 100 AS ARZFtPct,
((RetailNum/RetailDen) - SUM(Flowthru) /SUM(TotalCount)) / SQRT(((SUM(Flowthru) + RetailNum) / (SUM(TotalCount) +RetailDen)) * (1-(SUM(Flowthru)+RetailNum)/(SUM(TotalCount) + RetailDen)) * (1 / SUM(TotalCount)+1/RetailDen)) AS ZScoreMonth1
FROM pmMidwest33_BlueRed WHERE TotalCount <> 0 AND CLEC <>
'' AND Acna NOT IN ('TRE','TRD') AND STATE IN ('IL','IZ','TR','MI','RE')
AND MONTH(FromDate) = MONTH(DATEADD(m,-2,GETDATE()))
AND YEAR(FROMDATE) = YEAR(DATEADD(m,-2,GETDATE()))
GROUP BY FromDate,State,Description,RetailNum,RetailDenDid you figure what part of your SQL query returns a divide by zero ? It could be :
sum(TotalCount),
RetailDen,
SQRT(((SUM(Flowthru) + RetailNum)
...
Before casting anything, I would look for the origin of the problem.|||for example you have
select (SUM(Flowthru)/SUM(TotalCount)) * 100 AS CELCFtPct from table
select CELCFtPct = case when SUM(TotalCount)) = 0 then 0
else (SUM(Flowthru)/SUM(TotalCount)) * 100 end
from table
You can do that for all your divisions so you do not get division by zero error. Not sure what field you needed this on but its a good ideal to do this anytime that you are dividing because at some point you are bound to divide by zero.
Hope that helps
KG|||Thank you for your help.. I figured out that my data types needed to be changed to float. I had it a varchar.
Joe
Friday, March 9, 2012
divide by zero error
When I originally wrote the SQL below, I didn't think the last two fields
could ever be zero, but I was wrong. How can I rewrite this so if
NUM_PRODUCTION or NUM_PIECE_SIZE are zero, TotWithFuel simply equals zero?
SELECT
(dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_RATE +
(dbo.TDT_CUT_BLOCK_LGN_RATE.NUM_FUEL_RATE -
dbo.TDT_CUT_BLOCK_LGN_RATE.NUM_BASE_FUEL_RATE)
* dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_FUEL)
/ dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_PRODUCTION /
dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_PIECE_SIZE AS TotWithFuel
Thanks in advance!
AmberTry:
SELECT
isnull(
(dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_RATE +
(dbo.TDT_CUT_BLOCK_LGN_RATE.NUM_FUEL_RATE -
dbo.TDT_CUT_BLOCK_LGN_RATE.NUM_BASE_FUEL_RATE)
* dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_FUEL)
/
nullif(dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_PRODUCTION, 0) /
nullif(dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_PIECE_SIZE, 0)
, 0) AS TotWithFuel
AMB
"amber" wrote:
> Hello,
> When I originally wrote the SQL below, I didn't think the last two fields
> could ever be zero, but I was wrong. How can I rewrite this so if
> NUM_PRODUCTION or NUM_PIECE_SIZE are zero, TotWithFuel simply equals zero?
> SELECT
> (dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_RATE +
> (dbo.TDT_CUT_BLOCK_LGN_RATE.NUM_FUEL_RATE -
> dbo.TDT_CUT_BLOCK_LGN_RATE.NUM_BASE_FUEL_RATE)
> * dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_FUEL)
> / dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_PRODUCTION /
> dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_PIECE_SIZE AS TotWithFuel
> Thanks in advance!
> Amber|||"amber" <amber@.discussions.microsoft.com> wrote in message
news:50239A89-6D09-4DE2-805F-3A6E55FBEA4B@.microsoft.com...
> Hello,
> When I originally wrote the SQL below, I didn't think the last two fields
> could ever be zero, but I was wrong. How can I rewrite this so if
> NUM_PRODUCTION or NUM_PIECE_SIZE are zero, TotWithFuel simply equals zero?
> SELECT
> (dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_RATE +
> (dbo.TDT_CUT_BLOCK_LGN_RATE.NUM_FUEL_RATE -
> dbo.TDT_CUT_BLOCK_LGN_RATE.NUM_BASE_FUEL_RATE)
> * dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_FUEL)
> / dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_PRODUCTION /
> dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_PIECE_SIZE AS TotWithFuel
> Thanks in advance!
> Amber
SELECT
CASE WHEN dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_FUEL = 0 OR
dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_PIECE_SIZE = 0 THEN 0 ELSE
(dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_RATE +
(dbo.TDT_CUT_BLOCK_LGN_RATE.NUM_FUEL_RATE -
dbo.TDT_CUT_BLOCK_LGN_RATE.NUM_BASE_FUEL_RATE)
* dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_FUEL)
/ dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_PRODUCTION /
dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_PIECE_SIZE END AS TotWithFuel|||SELECT case when dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_PRODUCTION = 0 or
dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_PIECE_SIZE
= 0 then 0
else (dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_RATE +
(dbo.TDT_CUT_BLOCK_LGN_RATE.NUM_FUEL_RATE -
dbo.TDT_CUT_BLOCK_LGN_RATE.NUM_BASE_FUEL_RATE)
* dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_FUEL)
/
dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_PRODUCTION /
dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_PIECE_SIZE
end AS TotWithFuel
I would also consider using an alias on your tables to make it easier to
work with, at least to get rid of the dbo. in the column aliases. That
looks hard to read :)
just add AS <alias> like:
from dbo.tablename as tablename or something like this, but even shorter.
Don't lose the meaning of the name in the shortend version, thought. What
you have is better than using the kind of aliases some folks use: (A.? B.?
C.?) When you have like 10-15 tables in the query who knows what is going
on.
--
----
Louis Davidson - http://spaces.msn.com/members/drsql/
SQL Server MVP
"Arguments are to be avoided: they are always vulgar and often convincing."
(Oscar Wilde)
"amber" <amber@.discussions.microsoft.com> wrote in message
news:50239A89-6D09-4DE2-805F-3A6E55FBEA4B@.microsoft.com...
> Hello,
> When I originally wrote the SQL below, I didn't think the last two fields
> could ever be zero, but I was wrong. How can I rewrite this so if
> NUM_PRODUCTION or NUM_PIECE_SIZE are zero, TotWithFuel simply equals zero?
> SELECT
> (dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_RATE +
> (dbo.TDT_CUT_BLOCK_LGN_RATE.NUM_FUEL_RATE -
> dbo.TDT_CUT_BLOCK_LGN_RATE.NUM_BASE_FUEL_RATE)
> * dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_FUEL)
> / dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_PRODUCTION /
> dbo.TDT_CUT_BLOCK_LGN_FALLING.NUM_PIECE_SIZE AS TotWithFuel
> Thanks in advance!
> Amber
Divide by zero error
statements, all of the other expressions work fine except for this one below.
The proc that feeds the report does return 0's if there is no data. As of
now both fields have a value of zero, as time goes by there will be data. I
have other expressions that are all 0 and do not have any issues. I have
tried isNull, isNothing and the IIF. There are NO errors when I switch from
Layout to Preview, but the field has a ' #Error ' in preview mode. I am
sure it is somthing simple and obvious, but I am not seeing it. Can anyone
point me in the right direction? Thanks.
=IIF (Sum(Fields!lyYtdTotalWomen.Value,"proc" ) > 0 ,
Sum(Fields!lyYtdWomensClothing.Value,"proc") /
Sum(Fields!YtdTotalWomen.Value,"proc" ) , 0 )Try:
=iif((Sum(Fields!lyYtdWomensClothing.Value,"proc") /
Sum(Fields!YtdTotalWomen.Value,"proc" )) is
nothing,0,Sum(Fields!lyYtdWomensClothing.Value,"proc") /
Sum(Fields!YtdTotalWomen.Value,"proc" ))
darwin wrote:
> Hi all. I am succesfully catching divide by zero errors using IIF
> statements, all of the other expressions work fine except for this
one below.
> The proc that feeds the report does return 0's if there is no data.
As of
> now both fields have a value of zero, as time goes by there will be
data. I
> have other expressions that are all 0 and do not have any issues. I
have
> tried isNull, isNothing and the IIF. There are NO errors when I
switch from
> Layout to Preview, but the field has a ' #Error ' in preview mode.
I am
> sure it is somthing simple and obvious, but I am not seeing it. Can
anyone
> point me in the right direction? Thanks.
> =IIF (Sum(Fields!lyYtdTotalWomen.Value,"proc" ) > 0 ,
> Sum(Fields!lyYtdWomensClothing.Value,"proc") /
> Sum(Fields!YtdTotalWomen.Value,"proc" ) , 0 )|||Are you sure lyYtdWomensClothing is not returning zero...? Try using this
Sum(Fields!lyYtdTotalWomen.Value,"proc" ) > 0 AND
Sum(Fields!lyYtdWomensClothing.Value,"proc" ) > 0
for your IIF expression.
"darwin" wrote:
> Hi all. I am succesfully catching divide by zero errors using IIF
> statements, all of the other expressions work fine except for this one below.
> The proc that feeds the report does return 0's if there is no data. As of
> now both fields have a value of zero, as time goes by there will be data. I
> have other expressions that are all 0 and do not have any issues. I have
> tried isNull, isNothing and the IIF. There are NO errors when I switch from
> Layout to Preview, but the field has a ' #Error ' in preview mode. I am
> sure it is somthing simple and obvious, but I am not seeing it. Can anyone
> point me in the right direction? Thanks.
> =IIF (Sum(Fields!lyYtdTotalWomen.Value,"proc" ) > 0 ,
> Sum(Fields!lyYtdWomensClothing.Value,"proc") /
> Sum(Fields!YtdTotalWomen.Value,"proc" ) , 0 )|||nope, get a new error ... don't understand that one, the dataset is defined
on all fields in the expression.
h:\visual studio projects\paqs\PAQS Sales and Production.rdl The value
expression for the textbox â'textbox170â' refers to the field â'YtdTotalWomenâ'.
Report item expressions can only refer to fields within the current data set
scope or, if inside an aggregate, the specified data set scope.
"Michaema@.gmail.com" wrote:
> Try:
> =iif((Sum(Fields!lyYtdWomensClothing.Value,"proc") /
> Sum(Fields!YtdTotalWomen.Value,"proc" )) is
> nothing,0,Sum(Fields!lyYtdWomensClothing.Value,"proc") /
> Sum(Fields!YtdTotalWomen.Value,"proc" ))
> darwin wrote:
> > Hi all. I am succesfully catching divide by zero errors using IIF
> > statements, all of the other expressions work fine except for this
> one below.
> > The proc that feeds the report does return 0's if there is no data.
> As of
> > now both fields have a value of zero, as time goes by there will be
> data. I
> > have other expressions that are all 0 and do not have any issues. I
> have
> > tried isNull, isNothing and the IIF. There are NO errors when I
> switch from
> > Layout to Preview, but the field has a ' #Error ' in preview mode.
> I am
> > sure it is somthing simple and obvious, but I am not seeing it. Can
> anyone
> > point me in the right direction? Thanks.
> > =IIF (Sum(Fields!lyYtdTotalWomen.Value,"proc" ) > 0 ,
> > Sum(Fields!lyYtdWomensClothing.Value,"proc") /
> > Sum(Fields!YtdTotalWomen.Value,"proc" ) , 0 )
>|||I was under the impressiong that if you divide by 0 that Iif(a=0, 0,
b/a) was not enough. It will still try to evaluate both the true and
false parts before it picks which one to use. This has worked for me
in the past,
Iif(a=0, 0, b/Iif(a=0,1,a))
b/1 will never be the result but this will always evaluate.
I just deployed a custom assembly so I didn't have to write it like
this everyplace i wanted to use division.
Abe|||I think including the "proc" was causing some kind of error when it is
the expression being evaluated in an iif, try this and if that doesnt
work im out of ideas, i did have this same problem earlier, and the
format of this snippet below solved it.
=iif((Sum(Fields!lyYtdWomensClothing.Value) /
Sum(Fields!YtdTotalWomen.Value)) =nothing,0,Sum(Fields!lyYtdWomensClothing.Value) /
Sum(Fields!YtdTotalWomen.Value))|||I ran into the same situation. To solve it I set the textbox to hidden
if the divisor was zero. The true and false parts were always
evaluated giving me the error otherwise.
Roger|||If I remove the "proc" data set I get errors, there is more than one data set
in the report.
h:\visual studio projects\paqs\PAQS Sales and Production.rdl The value
expression for the textbox â'textbox170â' uses an aggregate expression without
a scope. A scope is required for all aggregates used outside of a data
region unless the report contains exactly one data set.
if I use this expression, there are no errors.. except for the " #Error "
message displayed on the preview page.
=iif( Sum(Fields!lyYtdTotalWomen.Value,"proc")
=0,0 , Sum(Fields!lyYtdWomensClothing.Value,"proc") /
Sum(Fields!lyYtdTotalWomen.Value,"proc")
)
Using Abe's Iif(a=0, 0, b/Iif(a=0,1,a)) formula, everthing is working and
happy! Thanks Greatly!!
"Alien2_51" wrote:
> Are you sure lyYtdWomensClothing is not returning zero...? Try using this
> Sum(Fields!lyYtdTotalWomen.Value,"proc" ) > 0 AND
> Sum(Fields!lyYtdWomensClothing.Value,"proc" ) > 0
> for your IIF expression.
> "darwin" wrote:
> > Hi all. I am succesfully catching divide by zero errors using IIF
> > statements, all of the other expressions work fine except for this one below.
> > The proc that feeds the report does return 0's if there is no data. As of
> > now both fields have a value of zero, as time goes by there will be data. I
> > have other expressions that are all 0 and do not have any issues. I have
> > tried isNull, isNothing and the IIF. There are NO errors when I switch from
> > Layout to Preview, but the field has a ' #Error ' in preview mode. I am
> > sure it is somthing simple and obvious, but I am not seeing it. Can anyone
> > point me in the right direction? Thanks.
> > =IIF (Sum(Fields!lyYtdTotalWomen.Value,"proc" ) > 0 ,
> > Sum(Fields!lyYtdWomensClothing.Value,"proc") /
> > Sum(Fields!YtdTotalWomen.Value,"proc" ) , 0 )|||I'm having similar problems with IIF and 'divide by zero' and liked your
solution below, but it still tells me it's dividing by zero. I'm also
retrieving the data from a stored procedure and have just the one dataset.
I even went as far as 'cast'ing all the data fields into the same datatype,
but that didn't help. Has anyone gotten the following IIF statement to work?
Here's my IIF statement, maybe I missed something..........
=iif((Fields!WNMHRS.Value=0),0.00,(
Fields!WJCHRS.Value/iif(Fields!WNMHRS.Value=0),1,Fields!WNMHRS.Value))
Thanks
"Abe" wrote:
> I was under the impressiong that if you divide by 0 that Iif(a=0, 0,
> b/a) was not enough. It will still try to evaluate both the true and
> false parts before it picks which one to use. This has worked for me
> in the past,
> Iif(a=0, 0, b/Iif(a=0,1,a))
> b/1 will never be the result but this will always evaluate.
> I just deployed a custom assembly so I didn't have to write it like
> this everyplace i wanted to use division.
> Abe
>|||> =iif((Fields!WNMHRS.Value=0),0.00,(
>
Fields!WJCHRS.Value/iif(Fields!WNMHRS.Value=0),1,Fields!WNMHRS.Value))
>
Should be
=iif((Fields!WNMHRS.Value=0),0.00,
Fields!WJCHRS.Value/iif(Fields!WNMHRS.Value=0,1,Fields!WNMHRS.Value))
I just took up the parenthesis in the front of the False part of the
first iff and removed an extra one in the middle of the second iif. I
think that should be ok...
Abe
DJanson wrote:
> I'm having similar problems with IIF and 'divide by zero' and liked
your
> solution below, but it still tells me it's dividing by zero. I'm
also
> retrieving the data from a stored procedure and have just the one
dataset.
> I even went as far as 'cast'ing all the data fields into the same
datatype,
> but that didn't help. Has anyone gotten the following IIF statement
to work?
>
> Here's my IIF statement, maybe I missed something..........
> =iif((Fields!WNMHRS.Value=0),0.00,(
>
Fields!WJCHRS.Value/iif(Fields!WNMHRS.Value=0),1,Fields!WNMHRS.Value))
> Thanks
> "Abe" wrote:
> > I was under the impressiong that if you divide by 0 that Iif(a=0,
0,
> > b/a) was not enough. It will still try to evaluate both the true
and
> > false parts before it picks which one to use. This has worked for
me
> > in the past,
> >
> > Iif(a=0, 0, b/Iif(a=0,1,a))
> > b/1 will never be the result but this will always evaluate.
> >
> > I just deployed a custom assembly so I didn't have to write it like
> > this everyplace i wanted to use division.
> >
> > Abe
> >
> >|||Hope I didn't look too stupid, I really tried LOTS of combinations using
parentheses and not using parentheses. I'm not used to seeing problems
putting parens around the conditional part of the statement, but guess that's
an issue here. Thanks.
"Abe" wrote:
> > =iif((Fields!WNMHRS.Value=0),0.00,(
> >
> Fields!WJCHRS.Value/iif(Fields!WNMHRS.Value=0),1,Fields!WNMHRS.Value))
> >
> Should be
> =iif((Fields!WNMHRS.Value=0),0.00,
> Fields!WJCHRS.Value/iif(Fields!WNMHRS.Value=0,1,Fields!WNMHRS.Value))
> I just took up the parenthesis in the front of the False part of the
> first iff and removed an extra one in the middle of the second iif. I
> think that should be ok...
> Abe
> DJanson wrote:
> > I'm having similar problems with IIF and 'divide by zero' and liked
> your
> > solution below, but it still tells me it's dividing by zero. I'm
> also
> > retrieving the data from a stored procedure and have just the one
> dataset.
> > I even went as far as 'cast'ing all the data fields into the same
> datatype,
> > but that didn't help. Has anyone gotten the following IIF statement
> to work?
> >
> >
> > Here's my IIF statement, maybe I missed something..........
> >
> > =iif((Fields!WNMHRS.Value=0),0.00,(
> >
> Fields!WJCHRS.Value/iif(Fields!WNMHRS.Value=0),1,Fields!WNMHRS.Value))
> >
> > Thanks
> >
> > "Abe" wrote:
> >
> > > I was under the impressiong that if you divide by 0 that Iif(a=0,
> 0,
> > > b/a) was not enough. It will still try to evaluate both the true
> and
> > > false parts before it picks which one to use. This has worked for
> me
> > > in the past,
> > >
> > > Iif(a=0, 0, b/Iif(a=0,1,a))
> > > b/1 will never be the result but this will always evaluate.
> > >
> > > I just deployed a custom assembly so I didn't have to write it like
> > > this everyplace i wanted to use division.
> > >
> > > Abe
> > >
> > >
>|||Yeah, no problem...I do it all the time. Sometimes its easier when
someone else looks at it :)
Abe
DJanson wrote:
> Hope I didn't look too stupid, I really tried LOTS of combinations
using
> parentheses and not using parentheses. I'm not used to seeing
problems
> putting parens around the conditional part of the statement, but
guess that's
> an issue here. Thanks.
> "Abe" wrote:
> > > =iif((Fields!WNMHRS.Value=0),0.00,(
> > >
> >
Fields!WJCHRS.Value/iif(Fields!WNMHRS.Value=0),1,Fields!WNMHRS.Value))
> > >
> >
> > Should be
> > =iif((Fields!WNMHRS.Value=0),0.00,
> >
Fields!WJCHRS.Value/iif(Fields!WNMHRS.Value=0,1,Fields!WNMHRS.Value))
> > I just took up the parenthesis in the front of the False part of
the
> > first iff and removed an extra one in the middle of the second iif.
I
> > think that should be ok...
> >
> > Abe
> > DJanson wrote:
> > > I'm having similar problems with IIF and 'divide by zero' and
liked
> > your
> > > solution below, but it still tells me it's dividing by zero. I'm
> > also
> > > retrieving the data from a stored procedure and have just the one
> > dataset.
> > > I even went as far as 'cast'ing all the data fields into the same
> > datatype,
> > > but that didn't help. Has anyone gotten the following IIF
statement
> > to work?
> > >
> > >
> > > Here's my IIF statement, maybe I missed something..........
> > >
> > > =iif((Fields!WNMHRS.Value=0),0.00,(
> > >
> >
Fields!WJCHRS.Value/iif(Fields!WNMHRS.Value=0),1,Fields!WNMHRS.Value))
> > >
> > > Thanks
> > >
> > > "Abe" wrote:
> > >
> > > > I was under the impressiong that if you divide by 0 that
Iif(a=0,
> > 0,
> > > > b/a) was not enough. It will still try to evaluate both the
true
> > and
> > > > false parts before it picks which one to use. This has worked
for
> > me
> > > > in the past,
> > > >
> > > > Iif(a=0, 0, b/Iif(a=0,1,a))
> > > > b/1 will never be the result but this will always evaluate.
> > > >
> > > > I just deployed a custom assembly so I didn't have to write it
like
> > > > this everyplace i wanted to use division.
> > > >
> > > > Abe
> > > >
> > > >
> >
> >|||I found a strange way to correct. Depending on your data accuracy
requirements, this may not work for you.
There is another post with instructions to hide the field if the divisor is
zero. This is the only way I have found if you need to show a zero on a
report. I am sure the math experts will not be happy with this one, but here
it is. Make sure to calculate your data & see how much inaccuracies it will
introduce. Use at your own risk!
Basically the both sides of the IIF statement are evaluated. Even though the
IIF should see the criteria & return "0", it doesn't.
I have found if you add a small number to the divisor, you don't see the
error.
=IIF (Sum(Fields!lyYtdTotalWomen.Value,"proc" ) > 0 ,
Sum(Fields!lyYtdWomensClothing.Value,"proc") /(
Sum(Fields!YtdTotalWomen.Value,"proc" ) + .0000000001 , 0 )
By adding .0000000001 you will not see the error, and assuming you are
calculating to 2 decimals, your accuracy should not be affected.
I have ran numerous scenarios & have not seen an accuracy problem when
rounding to 2 decimal points. I realize this is not the ideal solution as
it introduces inaccuracy. Hopefully in future versions there is another way
to handle.
Regards,
MB
"darwin" <darwin@.discussions.microsoft.com> wrote in message
news:7755D6FB-A5BD-41E4-BBBA-213907758B72@.microsoft.com...
> Hi all. I am succesfully catching divide by zero errors using IIF
> statements, all of the other expressions work fine except for this one
> below.
> The proc that feeds the report does return 0's if there is no data. As of
> now both fields have a value of zero, as time goes by there will be data.
> I
> have other expressions that are all 0 and do not have any issues. I have
> tried isNull, isNothing and the IIF. There are NO errors when I switch
> from
> Layout to Preview, but the field has a ' #Error ' in preview mode. I am
> sure it is somthing simple and obvious, but I am not seeing it. Can
> anyone
> point me in the right direction? Thanks.
> =IIF (Sum(Fields!lyYtdTotalWomen.Value,"proc" ) > 0 ,
> Sum(Fields!lyYtdWomensClothing.Value,"proc") /
> Sum(Fields!YtdTotalWomen.Value,"proc" ) , 0 )|||I finally got tired of writing cryptic IIF() expressions in order to handle
divide by zero conditions and wrote the following report function that can be
added to any report. it simplifies the appearance of the code, and lets you
specify an alternate value such as zero or nothing when divide by zero
occurs. I hope this is helpful...
' Handle divide by zero gracefully
' simpler than trying to use IIF()
Public Function CalcRatio(ByVal Numerator As Object, ByVal Denominator As
object, ByVal DivZeroDefault As Object) As Object
If Denominator <> 0 Then
Return Numerator/Denominator
Else
Return DivZeroDefault
End If
End Function
Steps:
From the menu, choose â'Reportâ', â'Report Propertiesâ'.
Click on the â'Codeâ' tab and past the above code into the window.
Click on â'OKâ'
To use the function, you have to reference the â'codeâ' collection in an
expression:
=code.CalcRatio( Fields!PYGrossProfit.Value, Fields!PYSales.Value, Nothing)
Or if you want a zero instead of a blank:
=code.CalcRatio( Fields!PYGrossProfit.Value, Fields!PYSales.Value, 0)
Enjoy!
--
Clayton Groom
Covenant Technology Parnters, LLC|||I realize this thread is almost 2 years old, but I hope someone can help out.
I have inserted the code below into my RS 2005 report,and get an error on
line 0.
"There is an error on line 0 of custom code: [BC30203] Identifier expected"
can anyone help?
thanks in advance
"Clayton Groom" wrote:
> I finally got tired of writing cryptic IIF() expressions in order to handle
> divide by zero conditions and wrote the following report function that can be
> added to any report. it simplifies the appearance of the code, and lets you
> specify an alternate value such as zero or nothing when divide by zero
> occurs. I hope this is helpful...
> ' Handle divide by zero gracefully
> ' simpler than trying to use IIF()
> Public Function CalcRatio(ByVal Numerator As Object, ByVal Denominator As
> object, ByVal DivZeroDefault As Object) As Object
> If Denominator <> 0 Then
> Return Numerator/Denominator
> Else
> Return DivZeroDefault
> End If
> End Function
> Steps:
> From the menu, choose â'Reportâ', â'Report Propertiesâ'.
> Click on the â'Codeâ' tab and past the above code into the window.
> Click on â'OKâ'
> To use the function, you have to reference the â'codeâ' collection in an
> expression:
> =code.CalcRatio( Fields!PYGrossProfit.Value, Fields!PYSales.Value, Nothing)
>
> Or if you want a zero instead of a blank:
> =code.CalcRatio( Fields!PYGrossProfit.Value, Fields!PYSales.Value, 0)
>
> Enjoy!
> --
> Clayton Groom
> Covenant Technology Parnters, LLC
>|||I'm very surprised no-one saw the problem with this:
=IIF (Sum(Fields!lyYtdTotalWomen.Value,"proc" ) > 0 ,
Sum(Fields!lyYtdWomensClothing.Value,"proc") /
Sum(Fields!YtdTotalWomen.Value,"proc" ) , 0 )
The IIF is checking lyYtdTotalWomen.Value, while the value used for division
is YtdTotalWomen.Value. Note the missing ly prefix. That makes them 2
different fields.
Divide By Zero - How to prevent
I am converting over a computer system from HQL to SQL and it has some
statements that I need to convert.
If you look at the below line of HQL code you will see the 'greatest'
function which as used prevents the divide by zero error under HQL. It works
on the absolute value of the second parameter so ( 100 - CurrentMargin(value
of 125) ) would equal 25 for the comparison of which is greater 1 or 25 but
does not impact the true value of -25. The main purpose is if the
CurrentMargin were to equal 100, subtracting it from 100 giving a value of 0
thus the greatest function would return a 1.
Select
ItemNum,
(CurrentMargin / greatest(1, (100 - CurrentMargin)) ) * InventoryTurns as
ROII
How can I rewrite it so that it prevents the divide by zero error if the
CurrentMargin is 100.
Sorry if I rambled on a bitMark,
You can use the SQL CASE expression:
select
ItemNum,
(
CurrentMargin
/
CASE WHEN 100-CurrentMargin < 1 THEN 1 ELSE 100 - CurrentMargin END
) * InventoryTurns as ROII
...
Steve Kass
Drew University
Mark Moss wrote:
>Gentle / Ladies
>
>I am converting over a computer system from HQL to SQL and it has some
>statements that I need to convert.
>If you look at the below line of HQL code you will see the 'greatest'
>function which as used prevents the divide by zero error under HQL. It work
s
>on the absolute value of the second parameter so ( 100 - CurrentMargin(valu
e
>of 125) ) would equal 25 for the comparison of which is greater 1 or 25 but
>does not impact the true value of -25. The main purpose is if the
>CurrentMargin were to equal 100, subtracting it from 100 giving a value of
0
>thus the greatest function would return a 1.
>Select
>ItemNum,
>(CurrentMargin / greatest(1, (100 - CurrentMargin)) ) * InventoryTurns as
>ROII
>How can I rewrite it so that it prevents the divide by zero error if the
>CurrentMargin is 100.
>Sorry if I rambled on a bit
>
>|||As I understand, if the CurrentMargin is 99.5, you do not really want
to divide by 1 (you want do divide by 100-99.5). In this case, you
might try:
SELECT ItemNum,
CurrentMargin/NULLIF(100-CurrentMargin,0)*InventoryTurns
...
or:
SELECT ItemNum,
CurrentMargin/ISNULL(NULLIF(100-CurrentMargin,0),1)*InventoryTurns
...
Razvan
Wednesday, March 7, 2012
distributor_admin
In my connection string as below , i have specified to use the user "sa"
but i am not sure why the error msg says login fail for distributor_admin
the server that i am connecting to is set up as a distirbutor on a local
publisher
strConn = "Provider=SQLOLEDB;Data Source=AAA;InititalCatalog
=master;uid=sa;pwd=XXXX"
appreciate any advice
tks & rdgs
Hi,
is there such a so called default password for this distributor_admin user ?
i can see that in the remote login , the sa is being mapped to the
distributor_admin when i tried to change it , it can be changed but once i
come it again it's still being mapped to distributor_admin
appreciate if someone could help
tks & rdgs
"maxzsim" wrote:
> Hi ,
> In my connection string as below , i have specified to use the user "sa"
> but i am not sure why the error msg says login fail for distributor_admin
> the server that i am connecting to is set up as a distirbutor on a local
> publisher
> strConn = "Provider=SQLOLEDB;Data Source=AAA;InititalCatalog
> =master;uid=sa;pwd=XXXX"
> appreciate any advice
> tks & rdgs
distributor_admin
In my connection string as below , i have specified to use the user "sa"
but i am not sure why the error msg says login fail for distributor_admin
the server that i am connecting to is set up as a distirbutor on a local
publisher
strConn = "Provider=SQLOLEDB;Data Source=AAA;InititalCatalog
=master;uid=sa;pwd=XXXX"
appreciate any advice
tks & rdgsHi,
is there such a so called default password for this distributor_admin user ?
i can see that in the remote login , the sa is being mapped to the
distributor_admin when i tried to change it , it can be changed but once i
come it again it's still being mapped to distributor_admin
appreciate if someone could help
tks & rdgs
"maxzsim" wrote:
> Hi ,
> In my connection string as below , i have specified to use the user "sa"
> but i am not sure why the error msg says login fail for distributor_admin
> the server that i am connecting to is set up as a distirbutor on a local
> publisher
> strConn = "Provider=SQLOLEDB;Data Source=AAA;InititalCatalog
> =master;uid=sa;pwd=XXXX"
> appreciate any advice
> tks & rdgs
distributor_admin
In my connection string as below , i have specified to use the user "sa"
but i am not sure why the error msg says login fail for distributor_admin
the server that i am connecting to is set up as a distirbutor on a local
publisher
strConn = "Provider=SQLOLEDB;Data Source=AAA;InititalCatalog
=master;uid=sa;pwd=XXXX"
appreciate any advice
tks & rdgsHi,
is there such a so called default password for this distributor_admin user ?
i can see that in the remote login , the sa is being mapped to the
distributor_admin when i tried to change it , it can be changed but once i
come it again it's still being mapped to distributor_admin
appreciate if someone could help
tks & rdgs
"maxzsim" wrote:
> Hi ,
> In my connection string as below , i have specified to use the user "sa"
> but i am not sure why the error msg says login fail for distributor_admin
> the server that i am connecting to is set up as a distirbutor on a local
> publisher
> strConn = "Provider=SQLOLEDB;Data Source=AAA;InititalCatalog
> =master;uid=sa;pwd=XXXX"
> appreciate any advice
> tks & rdgs
Friday, February 24, 2012
Distribution Agent Error (Timeout)
that timeout with errors listed below.
The databases were replication for two days without a
problem and I received the errors listed below.
Please help me resolve these errors.
Thank You,
Mike
Errors from Distribution Agent:
The process is running and is waiting for a response from
the backend connection.
{call sp_MSget_repl_commands(4, ?, 0, 7500000)}
Timeout expired
(Source: ODBC SQL Server Driver (ODBC); Error number:
S1T00)
sounds like you are replicating to Oracle? is this true?
The backend connection errors are hard to diagnose.
Enable replication logging and see if anything is going on
http://support.microsoft.com/default...b;EN-US;312292
Also change your inactivity threshhold to something large - right click on
replication monitor, select refresh rates.
If nothing is going on you should stop the agent and restart. If this fails
stop the sql agent service and restart, if this fails stop SQL Server and
restart, if this fails reboot.
If logging does reveal activity bump up your querytimeout setting to
something large - ie 1 hour and see what happens.
Exactly what are you doing that caused this to hang.
"Mike" <anonymous@.discussions.microsoft.com> wrote in message
news:1d0ea01c4230f$31615340$a301280a@.phx.gbl...
> I have SQL Server 2000 transactional replication databases
> that timeout with errors listed below.
> The databases were replication for two days without a
> problem and I received the errors listed below.
> Please help me resolve these errors.
> Thank You,
> Mike
>
> Errors from Distribution Agent:
> The process is running and is waiting for a response from
> the backend connection.
> {call sp_MSget_repl_commands(4, ?, 0, 7500000)}
> Timeout expired
> (Source: ODBC SQL Server Driver (ODBC); Error number:
> S1T00)
Friday, February 17, 2012
Distributed transaction error
I have written a procedure as below. I'm connected to a remote server server1 with valid
login id and permissions. When I run the procedure, I get the following error.
Server: Msg 7391, Level 16, State 1, Procedure procAddMissingAssociates, Line 09
The operation could not be performed because the OLE DB provider 'SQLOLEDB' does not support
distributed transactions.
[OLE/DB provider returned message: Distributed transaction error]
MSDTC is enabled on both the server, the local as well as the remote ones.
In the example below ASSOCIATE_ID in table2 is a primary key.
Please help,
Thanks
P.C. Vaidyanathan
CREATE PROCEDURE procAddMissingAssociates
AS
DECLARE @.USERID INT
BEGIN
SET TRANSACTION ISOLATION LEVEL repeatable read
BEGIN DISTRIBUTED TRANSACTION
SET XACT_ABORT ON
DECLARE MISSING_CURSOR CURSOR FOR
SELECT USR_ID
FROM SERVER1.DB1.DBO.TABLE1
WHERE USR_ID NOT IN (SELECT COLUMN2
FROM TABLE2)
OPEN MISSING_CURSOR
FETCH FROM MISSING_CURSOR
INTO @.USERID
WHILE (@.@.FETCH_STATUS=0)
BEGIN
INSERT INTO TABLE2 (ASSOCIATE_ID,
REDEEM_POINTS,
UPDATED_DATE)
VALUES (@.USERID,
0,
GETDATE())
FETCH NEXT FROM MISSING_CURSOR
INTO @.USERID
END
CLOSE MISSING_CURSOR
DEALLOCATE MISSING_CURSOR
COMMIT TRANSACTION
END
GOif your servers connect to each other trough the Firewall, check that all necessary ports are open in both directions. As usually it is 1433 and 134|||SERVER1.DB1.DBO.TABLE1
are both sql servers on the same network and starting as the same user? how are you authenticating with server1? linked server?
the above post is right, if you are on seperate networks, you'll need to have access to the other machine thru the firewall.
if you cant/dont want to setup a linked server, you can also use OPENROWSET in an encrypted view.
if thats not the problem.. from another forum
"To work around this problem, set XACT_ABORT to ON before the transaction. This causes SQL Server to terminate the surrounding transaction when an error occurs while processing the data modification statement. If SET XACT_ABORT is ON, SQL Server does not require nested transaction support from the OLE DB Provider. "
Also, try the following:
http://dbforums.com/t361216.html