I'm creating a report that selects data from one table. I'm trying to
add a parameter that will allow the user to select the data based on a
selection from one column (SpindleName). I've added this column in the
report parameters, checked the multi-value box, set the available
values to "from query" to the dataset & field, set the default values
to "from query" to the same dataset & field. When I execute the query,
I get asked for the SpindleName, but the box contains no values other
than "NULL" and "BLANK". If I type the spindle name into the box, I
get the results. Why isn't the list being populated with the values
from the spindlename column ?
Here is the query:
SELECT StationName, SpindleName, PartId, TimeStamp
FROM dbo.Readings
WHERE SpindleName IN (@.SpindleName)
I'm using SQL 2005 Express & VS 2005
Any advice would be appreciated.
Thank-you
JeffWhat is the source query for the parameter?
Alain Quesnel
alainsansspam@.logiquel.com
www.logiquel.com
"JMac" <jsvica1@.gmail.com> wrote in message
news:d6e84304-e8a6-489f-92df-17a10b7771d6@.25g2000hsx.googlegroups.com...
> I'm creating a report that selects data from one table. I'm trying to
> add a parameter that will allow the user to select the data based on a
> selection from one column (SpindleName). I've added this column in the
> report parameters, checked the multi-value box, set the available
> values to "from query" to the dataset & field, set the default values
> to "from query" to the same dataset & field. When I execute the query,
> I get asked for the SpindleName, but the box contains no values other
> than "NULL" and "BLANK". If I type the spindle name into the box, I
> get the results. Why isn't the list being populated with the values
> from the spindlename column ?
> Here is the query:
> SELECT StationName, SpindleName, PartId, TimeStamp
> FROM dbo.Readings
> WHERE SpindleName IN (@.SpindleName)
> I'm using SQL 2005 Express & VS 2005
> Any advice would be appreciated.
> Thank-you
> Jeff|||I may be wrong but it seems to me there is some confusion here. Several
things:
1. Unless you have cascading parameters (the list to select from parameter B
is dependent on the selection from parameter A) then you should have a query
that returns the value you want to select from.
2. Default means a single value. If you point to a dataset with multiple
values I don't know what it does except that is incorrect.
So, for instance by my take on this you want to this.
Have two datasets. One dataset that returns the list of SpindleName. The
other that retrieves the data you desire.
Select distinct SpindleName from Readings
Set both your label and value for the SpindleName parameter to the field
SpindleName from the above query.
Then your second query you have below will return what you want.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"JMac" <jsvica1@.gmail.com> wrote in message
news:d6e84304-e8a6-489f-92df-17a10b7771d6@.25g2000hsx.googlegroups.com...
> I'm creating a report that selects data from one table. I'm trying to
> add a parameter that will allow the user to select the data based on a
> selection from one column (SpindleName). I've added this column in the
> report parameters, checked the multi-value box, set the available
> values to "from query" to the dataset & field, set the default values
> to "from query" to the same dataset & field. When I execute the query,
> I get asked for the SpindleName, but the box contains no values other
> than "NULL" and "BLANK". If I type the spindle name into the box, I
> get the results. Why isn't the list being populated with the values
> from the spindlename column ?
> Here is the query:
> SELECT StationName, SpindleName, PartId, TimeStamp
> FROM dbo.Readings
> WHERE SpindleName IN (@.SpindleName)
> I'm using SQL 2005 Express & VS 2005
> Any advice would be appreciated.
> Thank-you
> Jeff|||For your point #2, if your parameter's default value points to a dataset
("From Query") with multiple values, they will show up with all of them
selected in the drop down list. This is desirable in some cases.
Alain Quesnel
alainsansspam@.logiquel.com
www.logiquel.com
"Bruce L-C [MVP]" <bruce_lcNOSPAM@.hotmail.com> wrote in message
news:%23P5CZRGrIHA.4376@.TK2MSFTNGP06.phx.gbl...
>I may be wrong but it seems to me there is some confusion here. Several
>things:
> 1. Unless you have cascading parameters (the list to select from parameter
> B is dependent on the selection from parameter A) then you should have a
> query that returns the value you want to select from.
> 2. Default means a single value. If you point to a dataset with multiple
> values I don't know what it does except that is incorrect.
> So, for instance by my take on this you want to this.
> Have two datasets. One dataset that returns the list of SpindleName. The
> other that retrieves the data you desire.
> Select distinct SpindleName from Readings
> Set both your label and value for the SpindleName parameter to the field
> SpindleName from the above query.
> Then your second query you have below will return what you want.
>
> --
> Bruce Loehle-Conger
> MVP SQL Server Reporting Services
> "JMac" <jsvica1@.gmail.com> wrote in message
> news:d6e84304-e8a6-489f-92df-17a10b7771d6@.25g2000hsx.googlegroups.com...
>> I'm creating a report that selects data from one table. I'm trying to
>> add a parameter that will allow the user to select the data based on a
>> selection from one column (SpindleName). I've added this column in the
>> report parameters, checked the multi-value box, set the available
>> values to "from query" to the dataset & field, set the default values
>> to "from query" to the same dataset & field. When I execute the query,
>> I get asked for the SpindleName, but the box contains no values other
>> than "NULL" and "BLANK". If I type the spindle name into the box, I
>> get the results. Why isn't the list being populated with the values
>> from the spindlename column ?
>> Here is the query:
>> SELECT StationName, SpindleName, PartId, TimeStamp
>> FROM dbo.Readings
>> WHERE SpindleName IN (@.SpindleName)
>> I'm using SQL 2005 Express & VS 2005
>> Any advice would be appreciated.
>> Thank-you
>> Jeff
>|||On May 2, 10:53=A0am, "Bruce L-C [MVP]" <bruce_lcNOS...@.hotmail.com>
wrote:
> I may be wrong but it seems to me there is some confusion here. Several
> things:
> 1. Unless you have cascading parameters (the list to select from parameter= B
> is dependent on the selection from parameter A) then you should have a que=ry
> that returns the value you want to select from.
> 2. Default means a single value. If you point to a dataset with multiple
> values I don't know what it does except that is incorrect.
> So, for instance by my take on this you want to this.
> Have two datasets. One dataset that returns the list of SpindleName. The
> other that retrieves the data you desire.
> Select distinct SpindleName from Readings
> Set both your label and value for the SpindleName parameter to the field
> SpindleName from the above query.
> Then your second query you have below will return what you want.
> --
> Bruce Loehle-Conger
> MVP SQL Server Reporting Services
> "JMac" <jsvi...@.gmail.com> wrote in message
> news:d6e84304-e8a6-489f-92df-17a10b7771d6@.25g2000hsx.googlegroups.com...
>
> > I'm creating a report that selects data from one table. I'm trying to
> > add a parameter that will allow the user to select the data based on a
> > selection from one column (SpindleName). I've added this column in the
> > report parameters, checked the multi-value box, set the available
> > values to "from query" to the dataset & field, set the default values
> > to "from query" to the same dataset & field. When I execute the query,
> > I get asked for the SpindleName, but the box contains no values other
> > than "NULL" and "BLANK". If I type the spindle name into the box, I
> > get the results. Why isn't the list being populated with the values
> > from the spindlename column ?
> > Here is the query:
> > SELECT StationName, SpindleName, PartId, TimeStamp
> > FROM dbo.Readings
> > WHERE SpindleName IN (@.SpindleName)
> > I'm using SQL 2005 Express & VS 2005
> > Any advice would be appreciated.
> > Thank-you
> > Jeff- Hide quoted text -
> - Show quoted text -
Thanks Bruce - it worked perfectly!
Regards
Jeff
Showing posts with label creating. Show all posts
Showing posts with label creating. Show all posts
Friday, March 30, 2012
Friday, March 23, 2012
Multiplication Aggregate
Howdy folks. I have a question about how to go about creating a function that will return the multiplication aggregate over a row. Essentially I need this to function in the exact same was as the sum() function, but with multiplication instead. I've been struggling trying to create a UDF to do this for me, but I'm not having much luck. I would be amazed if this is not something somebody else has already done out of necessity. Any ideas?Maybe you can show what formula you want to apply?|||Ok, how about:
USE Northwind
GO
CREATE FUNCTION udf_MULT (@.x float)
Returns float
AS
BEGIN
DECLARE @.y float
SELECT @.y = @.x * 2
RETURN @.y
END
GO
SELECT Freight, dbo.udf_MULT(Freight) FROM Orders
GO|||Brett, i don't think your udf_MULT is what Teddy wants
sample rows:
name value
foo 2
bar 4
qux 6
fap 8
select sum(value) from ... gives 20
select mult(value) from ..., assuming there were such an aggregate function as "mult()", would return 384
maybe a variation of that routine written up in that sqlteam article using coalesce to produce a comma-delimited list?
rudy|||You mean like:
USE Northwind
DECLARE @.x money
SELECT @.x = ISNULL(@.x,1) + Freight FROM Orders
SELECT @.x
I added them because of overflow...but you could use * instead...|||mmm, i love overflow
perhaps that's why "mult()" was never invented -- too easy to blow up the query real good
:)|||Add for the +, the ISNULL value should be 0, not 1...1 For Multiplication
hmmmmmmmmm...my cup runneth over with a flaming homer...or was that a flaming moe...
Hey...seeing it in type...
Noooow I get it...
Great episode...
Got to pick me up some cough medice on the way home...|||Thanks for the reply guys!!
I've been a bit busy with the holiday so I haven't had much time to make my rounds here. So far I've learned that this essentially is not possible with anything other then ints without a udf. Currently I'm searching for a udf that will do this for me, as I am not terribly familiar with coding them myself. Perhaps it's time to up the learning curve eh?|||a MULT function for varchar?
Hmmmm, now you've got me TOTALLY lost...
What exactly are you trying to do?|||Originally posted by Brett Kaiser
a MULT function for varchar?
Hmmmm, now you've got me TOTALLY lost...
What exactly are you trying to do?
Not for varchar, float. The closest I've found so far is sort of a bizarre workaround that doesn't seem to work properly over large recordsets:
EXP(SUM(LOG(value)))|||Originally posted by Brett Kaiser
What exactly are you trying to do?
Do you mean like what r937 said?
You can't (to my knowledge) create a user defined scalar function...
But you can employ the other method I posted
DECLARE @.x bigint
SELECT @.x = @.x + floatColumn FROM Table
SELECT @.x
Is that what you're trying to do? Multiply all the numbers in 1 column?|||Originally posted by Brett Kaiser
Do you mean like what r937 said?
You can't (to my knowledge) create a user defined scalar function...
But you can employ the other method I posted
DECLARE @.x bigint
SELECT @.x = @.x + floatColumn FROM Table
SELECT @.x
Is that what you're trying to do? Multiply all the numbers in 1 column?
That appears to be returning null. Does the select @.x = iterate through the entire recordset? I'm a bit new with variable usage in the queries themselves. Generally I would do this sort of thing at the application level with my front-end.|||Give this a read...
http://sqlteam.com/item.asp?ItemID=2368|||That appears to be returning nullhence the need for the COALESCE
and yes, you did mention this earlier, brett, but it's worth repeating -- 0 for addition, 1 for multiplication
:D|||Originally posted by r937
hence the need for the COALESCE
and yes, you did mention this earlier, brett, but it's worth repeating -- 0 for addition, 1 for multiplication
:D
Ok, I'm think I'm getting on the right track, but I am still not quite getting what I need. Currently I am using:
DECLARE @.x FLOAT
SELECT @.x = COALESCE(@.x, 1) * myField
FROM myTable
SELECT @.x
That is now returning 0.0 Oddly enough, if I use + instead of *, I return the same as SUM() + 1. So it does appear to function exactly as expected when applied to addition (the +1 is the result of using 0 as opposed to 1 for the null return), I'm still a bit stumped as to why it returns zero for multiplication. What am I overlooking?|||overlooking? probably precision and/or scale (i can never remember which is which)
try
SELECT @.x = COALESCE(@.x, 1.000000000) * myField|||Originally posted by r937
overlooking? probably precision and/or scale (i can never remember which is which)
try
SELECT @.x = COALESCE(@.x, 1.000000000) * myField
The issue was an overflow error. I ran the same syntax over a much smaller dataset and produced the desired result.
Thanks a bunch guys!!
This is at least enough to get me over the "how the hell..." hump that everyone hits once in a while.
Much obliged.|||And just for another twist...what if 1 of your rows has a 0
Come on...
puuuuleeeeeeeeeeeeze
Tell us this is more than an academic exercise...because I can't think of a practical application at all...|||Originally posted by Brett Kaiser
And just for another twist...what if 1 of your rows has a 0
Come on...
puuuuleeeeeeeeeeeeze
Tell us this is more than an academic exercise...because I can't think of a practical application at all...
The practical application is to a series of modifiers to an insurance quote. If one of them is zero, then the quote is free. I doubt that will happen.
:)|||So you have a very specific predicate...the quote...how many modifiers per quote on average?
...and if it can happen it will happen...just a matter of time...
CREATE TABLE myTable99 (Col1 int NOT NULL CONSTRAINT myTable99_chk1 CHECK (Col1 <> 0))|||Originally posted by Brett Kaiser
So you have a very specific predicate...the quote...how many modifiers per quote on average?
...and if it can happen it will happen...just a matter of time...
CREATE TABLE myTable99 (Col1 int NOT NULL CONSTRAINT myTable99_chk1 CHECK (Col1 <> 0))
approx 7-8 modifiers per quote. The mods tend to be in the .75 - 1.5 range. And it will never be 0. Not unless the chairman of the board owes someone a serious favor. In which case, that's really not my problem to begin with.
The issue is the varying number of modfiers for each quote. Some will only have one, some will have 8. That's why this mult function comes in handy. This is fairly easy to do client-side, but for some reason is murderous to do in sql until this morning.|||So you would check to see if the result of this multiplier function is zero, and then act accordingly?
There are other methods that might work. For instance:
select min(Abs(YourColumn))
...would return zero if any of the values is zero.
blindman|||...and you can include this directly in a calculation:
Cost * cast(cast(min(Abs(YourColumn)) as bit) as int)
...would result in a cost of $0 if any of the multipliers is zero.
blindman|||Originally posted by blindman
...and you can include this directly in a calculation:
Cost * cast(cast(min(Abs(YourColumn)) as bit) as int)
...would result in a cost of $0 if any of the multipliers is zero.
blindman
That's really not an issue. This is well and solved.
Anywho, the current method would return 0 as-is.|||Originally posted by Teddy
Not for varchar, float. The closest I've found so far is sort of a bizarre workaround that doesn't seem to work properly over large recordsets:
EXP(SUM(LOG(value)))
I do like the workaround solution. Could you tell me what do you mean by "doesn't seem to work properly over large recordsets"? Is it the overflow problem? I tested it on a table of 4000 records, the results is as expected.|||Originally posted by shianmiin
I do like the workaround solution. Could you tell me what do you mean by "doesn't seem to work properly over large recordsets"? Is it the overflow problem?
edit: read that wrong.
I'm not sure what the issue is. It returns nothing at all when I use a large set. Very odd.|||Originally posted by Teddy
edit: read that wrong.
I'm not sure what the issue is. It returns nothing at all when I use a large set. Very odd.
for actual cases, i.e.
approx 7-8 modifiers per quote. The mods tend to be in the .75 - 1.5 range. And it will never be 0. Not unless the chairman of the board owes someone a serious favor.
I think this would be a best solution to me. :)
select
case
when min(isnull(f1, 0))=0 then 0
else exp(sum(log(isnull(case when f1=0 then 1 else f1 end,1))))
end
from t1
The query posted handles zero and null value correctly.
And I don't think overflow would be a problem.
(There shouldn't be negative values in the table, if it is, you need to add some code to handle it properly)|||The issue is:
USE Northwind
GO
DECLARE @.x BIGINT
SELECT @.x = 1
--Wont Blow Up
SELECT @.x = @.x * ISNULL(EmployeeId,1)
FROM Orders
WHERE EmployeeId = 1
SELECT @.@.ERROR AS ErrorCode
--Will Blow Up
SELECT @.x
SELECT @.x = 1
SELECT @.x = @.x * ISNULL(EmployeeId,1)
FROM Orders
WHERE EmployeeId = 2
SELECT @.@.ERROR AS ErrorCode
SELECT @.x
--The error should read:
-- Server: Msg 8115, Level 16, State 2, Line 11
-- Arithmetic overflow error converting expression to data type bigint.
In any event, error checking is a must...for all code...|||Originally posted by Brett Kaiser
The issue is:
USE Northwind
GO
DECLARE @.x BIGINT
SELECT @.x = 1
--Wont Blow Up
SELECT @.x = @.x * ISNULL(EmployeeId,1)
FROM Orders
WHERE EmployeeId = 1
SELECT @.@.ERROR AS ErrorCode
--Will Blow Up
SELECT @.x
SELECT @.x = 1
SELECT @.x = @.x * ISNULL(EmployeeId,1)
FROM Orders
WHERE EmployeeId = 2
SELECT @.@.ERROR AS ErrorCode
SELECT @.x
--The error should read:
-- Server: Msg 8115, Level 16, State 2, Line 11
-- Arithmetic overflow error converting expression to data type bigint.
In any event, error checking is a must...for all code...
Since the query returns float, the range would be - 1.79E + 308 through 1.79E + 308, that's what I meant that overflow shouldn't be a problem for actual situration. To prevent errors of overflow, the query may check the value before applying EXP(), that would be something like
case
when sum(log(...)) > 307 then ... -- overflow
when sum(log(...)) < -307 then ... -- underflow
else exp(sum(log(...)))
end|||Ahhh proactive error handling...very nice...
just watch...the [banging head]overhead[/banging head] for some statements...|||Originally posted by Brett Kaiser
Ahhh proactive error handling...very nice...
just watch...the [banging head]overhead[/banging head] for some statements...
I agree that the overhead should be considered. Normally procedural statements have more control over what needs to be done while combination of functions tends to make code look neat. Which choice to go would depends on actual siturations. :)
USE Northwind
GO
CREATE FUNCTION udf_MULT (@.x float)
Returns float
AS
BEGIN
DECLARE @.y float
SELECT @.y = @.x * 2
RETURN @.y
END
GO
SELECT Freight, dbo.udf_MULT(Freight) FROM Orders
GO|||Brett, i don't think your udf_MULT is what Teddy wants
sample rows:
name value
foo 2
bar 4
qux 6
fap 8
select sum(value) from ... gives 20
select mult(value) from ..., assuming there were such an aggregate function as "mult()", would return 384
maybe a variation of that routine written up in that sqlteam article using coalesce to produce a comma-delimited list?
rudy|||You mean like:
USE Northwind
DECLARE @.x money
SELECT @.x = ISNULL(@.x,1) + Freight FROM Orders
SELECT @.x
I added them because of overflow...but you could use * instead...|||mmm, i love overflow
perhaps that's why "mult()" was never invented -- too easy to blow up the query real good
:)|||Add for the +, the ISNULL value should be 0, not 1...1 For Multiplication
hmmmmmmmmm...my cup runneth over with a flaming homer...or was that a flaming moe...
Hey...seeing it in type...
Noooow I get it...
Great episode...
Got to pick me up some cough medice on the way home...|||Thanks for the reply guys!!
I've been a bit busy with the holiday so I haven't had much time to make my rounds here. So far I've learned that this essentially is not possible with anything other then ints without a udf. Currently I'm searching for a udf that will do this for me, as I am not terribly familiar with coding them myself. Perhaps it's time to up the learning curve eh?|||a MULT function for varchar?
Hmmmm, now you've got me TOTALLY lost...
What exactly are you trying to do?|||Originally posted by Brett Kaiser
a MULT function for varchar?
Hmmmm, now you've got me TOTALLY lost...
What exactly are you trying to do?
Not for varchar, float. The closest I've found so far is sort of a bizarre workaround that doesn't seem to work properly over large recordsets:
EXP(SUM(LOG(value)))|||Originally posted by Brett Kaiser
What exactly are you trying to do?
Do you mean like what r937 said?
You can't (to my knowledge) create a user defined scalar function...
But you can employ the other method I posted
DECLARE @.x bigint
SELECT @.x = @.x + floatColumn FROM Table
SELECT @.x
Is that what you're trying to do? Multiply all the numbers in 1 column?|||Originally posted by Brett Kaiser
Do you mean like what r937 said?
You can't (to my knowledge) create a user defined scalar function...
But you can employ the other method I posted
DECLARE @.x bigint
SELECT @.x = @.x + floatColumn FROM Table
SELECT @.x
Is that what you're trying to do? Multiply all the numbers in 1 column?
That appears to be returning null. Does the select @.x = iterate through the entire recordset? I'm a bit new with variable usage in the queries themselves. Generally I would do this sort of thing at the application level with my front-end.|||Give this a read...
http://sqlteam.com/item.asp?ItemID=2368|||That appears to be returning nullhence the need for the COALESCE
and yes, you did mention this earlier, brett, but it's worth repeating -- 0 for addition, 1 for multiplication
:D|||Originally posted by r937
hence the need for the COALESCE
and yes, you did mention this earlier, brett, but it's worth repeating -- 0 for addition, 1 for multiplication
:D
Ok, I'm think I'm getting on the right track, but I am still not quite getting what I need. Currently I am using:
DECLARE @.x FLOAT
SELECT @.x = COALESCE(@.x, 1) * myField
FROM myTable
SELECT @.x
That is now returning 0.0 Oddly enough, if I use + instead of *, I return the same as SUM() + 1. So it does appear to function exactly as expected when applied to addition (the +1 is the result of using 0 as opposed to 1 for the null return), I'm still a bit stumped as to why it returns zero for multiplication. What am I overlooking?|||overlooking? probably precision and/or scale (i can never remember which is which)
try
SELECT @.x = COALESCE(@.x, 1.000000000) * myField|||Originally posted by r937
overlooking? probably precision and/or scale (i can never remember which is which)
try
SELECT @.x = COALESCE(@.x, 1.000000000) * myField
The issue was an overflow error. I ran the same syntax over a much smaller dataset and produced the desired result.
Thanks a bunch guys!!
This is at least enough to get me over the "how the hell..." hump that everyone hits once in a while.
Much obliged.|||And just for another twist...what if 1 of your rows has a 0
Come on...
puuuuleeeeeeeeeeeeze
Tell us this is more than an academic exercise...because I can't think of a practical application at all...|||Originally posted by Brett Kaiser
And just for another twist...what if 1 of your rows has a 0
Come on...
puuuuleeeeeeeeeeeeze
Tell us this is more than an academic exercise...because I can't think of a practical application at all...
The practical application is to a series of modifiers to an insurance quote. If one of them is zero, then the quote is free. I doubt that will happen.
:)|||So you have a very specific predicate...the quote...how many modifiers per quote on average?
...and if it can happen it will happen...just a matter of time...
CREATE TABLE myTable99 (Col1 int NOT NULL CONSTRAINT myTable99_chk1 CHECK (Col1 <> 0))|||Originally posted by Brett Kaiser
So you have a very specific predicate...the quote...how many modifiers per quote on average?
...and if it can happen it will happen...just a matter of time...
CREATE TABLE myTable99 (Col1 int NOT NULL CONSTRAINT myTable99_chk1 CHECK (Col1 <> 0))
approx 7-8 modifiers per quote. The mods tend to be in the .75 - 1.5 range. And it will never be 0. Not unless the chairman of the board owes someone a serious favor. In which case, that's really not my problem to begin with.
The issue is the varying number of modfiers for each quote. Some will only have one, some will have 8. That's why this mult function comes in handy. This is fairly easy to do client-side, but for some reason is murderous to do in sql until this morning.|||So you would check to see if the result of this multiplier function is zero, and then act accordingly?
There are other methods that might work. For instance:
select min(Abs(YourColumn))
...would return zero if any of the values is zero.
blindman|||...and you can include this directly in a calculation:
Cost * cast(cast(min(Abs(YourColumn)) as bit) as int)
...would result in a cost of $0 if any of the multipliers is zero.
blindman|||Originally posted by blindman
...and you can include this directly in a calculation:
Cost * cast(cast(min(Abs(YourColumn)) as bit) as int)
...would result in a cost of $0 if any of the multipliers is zero.
blindman
That's really not an issue. This is well and solved.
Anywho, the current method would return 0 as-is.|||Originally posted by Teddy
Not for varchar, float. The closest I've found so far is sort of a bizarre workaround that doesn't seem to work properly over large recordsets:
EXP(SUM(LOG(value)))
I do like the workaround solution. Could you tell me what do you mean by "doesn't seem to work properly over large recordsets"? Is it the overflow problem? I tested it on a table of 4000 records, the results is as expected.|||Originally posted by shianmiin
I do like the workaround solution. Could you tell me what do you mean by "doesn't seem to work properly over large recordsets"? Is it the overflow problem?
edit: read that wrong.
I'm not sure what the issue is. It returns nothing at all when I use a large set. Very odd.|||Originally posted by Teddy
edit: read that wrong.
I'm not sure what the issue is. It returns nothing at all when I use a large set. Very odd.
for actual cases, i.e.
approx 7-8 modifiers per quote. The mods tend to be in the .75 - 1.5 range. And it will never be 0. Not unless the chairman of the board owes someone a serious favor.
I think this would be a best solution to me. :)
select
case
when min(isnull(f1, 0))=0 then 0
else exp(sum(log(isnull(case when f1=0 then 1 else f1 end,1))))
end
from t1
The query posted handles zero and null value correctly.
And I don't think overflow would be a problem.
(There shouldn't be negative values in the table, if it is, you need to add some code to handle it properly)|||The issue is:
USE Northwind
GO
DECLARE @.x BIGINT
SELECT @.x = 1
--Wont Blow Up
SELECT @.x = @.x * ISNULL(EmployeeId,1)
FROM Orders
WHERE EmployeeId = 1
SELECT @.@.ERROR AS ErrorCode
--Will Blow Up
SELECT @.x
SELECT @.x = 1
SELECT @.x = @.x * ISNULL(EmployeeId,1)
FROM Orders
WHERE EmployeeId = 2
SELECT @.@.ERROR AS ErrorCode
SELECT @.x
--The error should read:
-- Server: Msg 8115, Level 16, State 2, Line 11
-- Arithmetic overflow error converting expression to data type bigint.
In any event, error checking is a must...for all code...|||Originally posted by Brett Kaiser
The issue is:
USE Northwind
GO
DECLARE @.x BIGINT
SELECT @.x = 1
--Wont Blow Up
SELECT @.x = @.x * ISNULL(EmployeeId,1)
FROM Orders
WHERE EmployeeId = 1
SELECT @.@.ERROR AS ErrorCode
--Will Blow Up
SELECT @.x
SELECT @.x = 1
SELECT @.x = @.x * ISNULL(EmployeeId,1)
FROM Orders
WHERE EmployeeId = 2
SELECT @.@.ERROR AS ErrorCode
SELECT @.x
--The error should read:
-- Server: Msg 8115, Level 16, State 2, Line 11
-- Arithmetic overflow error converting expression to data type bigint.
In any event, error checking is a must...for all code...
Since the query returns float, the range would be - 1.79E + 308 through 1.79E + 308, that's what I meant that overflow shouldn't be a problem for actual situration. To prevent errors of overflow, the query may check the value before applying EXP(), that would be something like
case
when sum(log(...)) > 307 then ... -- overflow
when sum(log(...)) < -307 then ... -- underflow
else exp(sum(log(...)))
end|||Ahhh proactive error handling...very nice...
just watch...the [banging head]overhead[/banging head] for some statements...|||Originally posted by Brett Kaiser
Ahhh proactive error handling...very nice...
just watch...the [banging head]overhead[/banging head] for some statements...
I agree that the overhead should be considered. Normally procedural statements have more control over what needs to be done while combination of functions tends to make code look neat. Which choice to go would depends on actual siturations. :)
Friday, March 9, 2012
Multiple Table Queries
I am having propblems creating a multiple table query for a stored procedure.
Here is what I have..
db1 = transaction database with multipke fields keyed on transid, and membid
db2 = transaction legal details keyed on transid & legalid
db3 = member details keyed on membid & officeid
db4 = office details keyed on officeid & membid
What I am after is a query which will result in ALL details being returned for a particular transaction
ie. transaction detail, legal detail, member detail & office detail...
please helpsomething like...
select db1.*, db2.*, db3.*, db4.*
from db1
join db2 on db1.transid = db2.transid
join db3 on db1.membid = db3.membid
join db4 on db3.officeid = db4.officeid|||Thanks, worked like a charm.
Much Obliged.. have more queries to do for this project, I am sure I will have more posts for you.
Here is what I have..
db1 = transaction database with multipke fields keyed on transid, and membid
db2 = transaction legal details keyed on transid & legalid
db3 = member details keyed on membid & officeid
db4 = office details keyed on officeid & membid
What I am after is a query which will result in ALL details being returned for a particular transaction
ie. transaction detail, legal detail, member detail & office detail...
please helpsomething like...
select db1.*, db2.*, db3.*, db4.*
from db1
join db2 on db1.transid = db2.transid
join db3 on db1.membid = db3.membid
join db4 on db3.officeid = db4.officeid|||Thanks, worked like a charm.
Much Obliged.. have more queries to do for this project, I am sure I will have more posts for you.
Saturday, February 25, 2012
Multiple Selections and MDX
I am creating a report that the user wants to have mulitple parameters
but I am querying an OLAP Cube. Is there a way of building a query on
the fly depending on users selection. Fopr example in SQL you could say
"IN (Parameters!MyParam.Value)" is it possible to do something like
this in MDX or do I just have to query everything and filder using the
Report Parameter
Thanks in advance
DenverYes, you can do this pretty much the way you described. You're
building a string which is the mdx query and adding the parameters as
you do this. Can't remember the exact syntax I used, but it amounts
to:
"mdx_part1" + Parameters!MyParam.Value + "mdx_part2"|||How will this work for multiple selections?
but I am querying an OLAP Cube. Is there a way of building a query on
the fly depending on users selection. Fopr example in SQL you could say
"IN (Parameters!MyParam.Value)" is it possible to do something like
this in MDX or do I just have to query everything and filder using the
Report Parameter
Thanks in advance
DenverYes, you can do this pretty much the way you described. You're
building a string which is the mdx query and adding the parameters as
you do this. Can't remember the exact syntax I used, but it amounts
to:
"mdx_part1" + Parameters!MyParam.Value + "mdx_part2"|||How will this work for multiple selections?
Subscribe to:
Posts (Atom)