Showing posts with label case. Show all posts
Showing posts with label case. Show all posts

Monday, March 19, 2012

How can you use an IN statement with a CASE statement

I am trying to run a query that filters using an IN statment, but the
IN statement needs to be dynamically generated based upon some
criteria. Here is my example:
DECLARE @.tempTable TABLE
(
letter char(1),
id int
)
INSERT INTO @.tempTable VALUES ('A', 1)
INSERT INTO @.tempTable VALUES ('B', 2)
INSERT INTO @.tempTable VALUES ('C', 3)
SELECT * FROM @.tempTable WHERE letter IN
(Case 2
WHEN 1 THEN ('A')
WHEN 2 THEN ('B', 'C')
END)
If you try to run this code, it gives an error on the line that
contains the 'B', 'C' (incorrect syntax near ',').
If you remove the C and just leave the two lines, one with A, one with
B, then it will work as expected.
I can't make head or tail of what you are trying to do here (mostly because
of the 'Case 2' which will always try to run the B,C variant), but in any
case, an IN list cannot be the result of a CASE expression.
Maybe you meant something like this (wild guesses here):
DECLARE @.tinyint TINYINT;
SET @.tinyint = 2;
SELECT * FROM @.temptable
WHERE @.tinyint = CASE
WHEN letter = 'A' THEN 1
WHEN letter IN ('B','C') THEN2
END
The important thing to remember is that CASE is not for control of flow, it
is an expression that returns exactly one datatype, and all possible
outcomes must be able to yield the same datatype (or NULL).
Maybe you could try with a slightly more realistic example of what you are
really trying to accomplish, with real sample data and real desired results.
I can't deduce anything from A,B,C.
A
<MatthewSumpter@.gmail.com> wrote in message
news:1167774294.707435.113300@.42g2000cwt.googlegro ups.com...
>I am trying to run a query that filters using an IN statment, but the
> IN statement needs to be dynamically generated based upon some
> criteria. Here is my example:
> DECLARE @.tempTable TABLE
> (
> letter char(1),
> id int
> )
> INSERT INTO @.tempTable VALUES ('A', 1)
> INSERT INTO @.tempTable VALUES ('B', 2)
> INSERT INTO @.tempTable VALUES ('C', 3)
> SELECT * FROM @.tempTable WHERE letter IN
> (Case 2
> WHEN 1 THEN ('A')
> WHEN 2 THEN ('B', 'C')
> END)
>
> If you try to run this code, it gives an error on the line that
> contains the 'B', 'C' (incorrect syntax near ',').
> If you remove the C and just leave the two lines, one with A, one with
> B, then it will work as expected.
>
|||OK,
Sorry that my example isn't the easiest to understand. I was actually
just trying to make it more readable. If it's true that the CASE
expression cannot return more than one value (such as an IN list), then
I may need to take another approach, but let me at least give you a
better example.
Let's say I have a table with products in it. Each product has a
category #.
Categories:
1 Shoes
2 Pants
3 Shirts
4 TVs
5 DVD Players
6 Xboxes
Now I want to do a select statement based upon a category type passed
into the procedure @.CategoryType. When @.CategoryType is "electronics",
I want to return all products with category numbers 4, 5, or 6.
Likewise, if "clothing" is passed in, I want to return all products
with 1, 2, 3.
SELECT * FROM Products WHERE CategoryID IN
(CASE @.CategoryType
WHEN "electronics" THEN (4,5,6)
WHEN "clothing" THEN (1,2,3)
END)
Hopefully, this makes more sense.
Thanks,
Matthew
Aaron Bertrand [SQL Server MVP] wrote:[vbcol=seagreen]
> I can't make head or tail of what you are trying to do here (mostly because
> of the 'Case 2' which will always try to run the B,C variant), but in any
> case, an IN list cannot be the result of a CASE expression.
> Maybe you meant something like this (wild guesses here):
> DECLARE @.tinyint TINYINT;
> SET @.tinyint = 2;
> SELECT * FROM @.temptable
> WHERE @.tinyint = CASE
> WHEN letter = 'A' THEN 1
> WHEN letter IN ('B','C') THEN2
> END
> The important thing to remember is that CASE is not for control of flow, it
> is an expression that returns exactly one datatype, and all possible
> outcomes must be able to yield the same datatype (or NULL).
> Maybe you could try with a slightly more realistic example of what you are
> really trying to accomplish, with real sample data and real desired results.
> I can't deduce anything from A,B,C.
> A
>
> <MatthewSumpter@.gmail.com> wrote in message
> news:1167774294.707435.113300@.42g2000cwt.googlegro ups.com...

How can you use an IN statement with a CASE statement

I am trying to run a query that filters using an IN statment, but the
IN statement needs to be dynamically generated based upon some
criteria. Here is my example:
DECLARE @.tempTable TABLE
(
letter char(1),
id int
)
INSERT INTO @.tempTable VALUES ('A', 1)
INSERT INTO @.tempTable VALUES ('B', 2)
INSERT INTO @.tempTable VALUES ('C', 3)
SELECT * FROM @.tempTable WHERE letter IN
(Case 2
WHEN 1 THEN ('A')
WHEN 2 THEN ('B', 'C')
END)
If you try to run this code, it gives an error on the line that
contains the 'B', 'C' (incorrect syntax near ',').
If you remove the C and just leave the two lines, one with A, one with
B, then it will work as expected.I can't make head or tail of what you are trying to do here (mostly because
of the 'Case 2' which will always try to run the B,C variant), but in any
case, an IN list cannot be the result of a CASE expression.
Maybe you meant something like this (wild guesses here):
DECLARE @.tinyint TINYINT;
SET @.tinyint = 2;
SELECT * FROM @.temptable
WHERE @.tinyint = CASE
WHEN letter = 'A' THEN 1
WHEN letter IN ('B','C') THEN2
END
The important thing to remember is that CASE is not for control of flow, it
is an expression that returns exactly one datatype, and all possible
outcomes must be able to yield the same datatype (or NULL).
Maybe you could try with a slightly more realistic example of what you are
really trying to accomplish, with real sample data and real desired results.
I can't deduce anything from A,B,C.
A
<MatthewSumpter@.gmail.com> wrote in message
news:1167774294.707435.113300@.42g2000cwt.googlegroups.com...
>I am trying to run a query that filters using an IN statment, but the
> IN statement needs to be dynamically generated based upon some
> criteria. Here is my example:
> DECLARE @.tempTable TABLE
> (
> letter char(1),
> id int
> )
> INSERT INTO @.tempTable VALUES ('A', 1)
> INSERT INTO @.tempTable VALUES ('B', 2)
> INSERT INTO @.tempTable VALUES ('C', 3)
> SELECT * FROM @.tempTable WHERE letter IN
> (Case 2
> WHEN 1 THEN ('A')
> WHEN 2 THEN ('B', 'C')
> END)
>
> If you try to run this code, it gives an error on the line that
> contains the 'B', 'C' (incorrect syntax near ',').
> If you remove the C and just leave the two lines, one with A, one with
> B, then it will work as expected.
>|||OK,
Sorry that my example isn't the easiest to understand. I was actually
just trying to make it more readable. If it's true that the CASE
expression cannot return more than one value (such as an IN list), then
I may need to take another approach, but let me at least give you a
better example.
Let's say I have a table with products in it. Each product has a
category #.
Categories:
1 Shoes
2 Pants
3 Shirts
4 TVs
5 DVD Players
6 Xboxes
Now I want to do a select statement based upon a category type passed
into the procedure @.CategoryType. When @.CategoryType is "electronics",
I want to return all products with category numbers 4, 5, or 6.
Likewise, if "clothing" is passed in, I want to return all products
with 1, 2, 3.
SELECT * FROM Products WHERE CategoryID IN
(CASE @.CategoryType
WHEN "electronics" THEN (4,5,6)
WHEN "clothing" THEN (1,2,3)
END)
Hopefully, this makes more sense.
Thanks,
Matthew
Aaron Bertrand [SQL Server MVP] wrote:[vbcol=seagreen]
> I can't make head or tail of what you are trying to do here (mostly becaus
e
> of the 'Case 2' which will always try to run the B,C variant), but in any
> case, an IN list cannot be the result of a CASE expression.
> Maybe you meant something like this (wild guesses here):
> DECLARE @.tinyint TINYINT;
> SET @.tinyint = 2;
> SELECT * FROM @.temptable
> WHERE @.tinyint = CASE
> WHEN letter = 'A' THEN 1
> WHEN letter IN ('B','C') THEN2
> END
> The important thing to remember is that CASE is not for control of flow, i
t
> is an expression that returns exactly one datatype, and all possible
> outcomes must be able to yield the same datatype (or NULL).
> Maybe you could try with a slightly more realistic example of what you are
> really trying to accomplish, with real sample data and real desired result
s.
> I can't deduce anything from A,B,C.
> A
>
> <MatthewSumpter@.gmail.com> wrote in message
> news:1167774294.707435.113300@.42g2000cwt.googlegroups.com...|||On 3 Jan 2007 06:50:11 -0800, Loganx80 wrote:

>OK,
>Sorry that my example isn't the easiest to understand. I was actually
>just trying to make it more readable. If it's true that the CASE
>expression cannot return more than one value (such as an IN list), then
>I may need to take another approach, but let me at least give you a
>better example.
>Let's say I have a table with products in it. Each product has a
>category #.
>Categories:
>1 Shoes
>2 Pants
>3 Shirts
>4 TVs
>5 DVD Players
>6 Xboxes
>Now I want to do a select statement based upon a category type passed
>into the procedure @.CategoryType. When @.CategoryType is "electronics",
>I want to return all products with category numbers 4, 5, or 6.
>Likewise, if "clothing" is passed in, I want to return all products
>with 1, 2, 3.
>SELECT * FROM Products WHERE CategoryID IN
> (CASE @.CategoryType
> WHEN "electronics" THEN (4,5,6)
> WHEN "clothing" THEN (1,2,3)
> END)
>
>Hopefully, this makes more sense.
Hi Matthew,
Best way to do this is to add a categories table with a CategoryID and a
CategoryType column. That way, you can add products (and categories!)
without having to change any queries. I have always hated hard-coded
magic values.
But if you do want to hard-code the values, try something like this
SELECT Col1, Col2, ... -- Never use SELECT * !!!
FROM Products
WHERE (@.CategoryType = 'electronics' AND CategoryID IN (4, 5, 6))
OR (@.CategoryType = 'clothing' AND CategoryID IN (1, 2, 3));
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis

How can you use an IN statement with a CASE statement

I am trying to run a query that filters using an IN statment, but the
IN statement needs to be dynamically generated based upon some
criteria. Here is my example:
DECLARE @.tempTable TABLE
(
letter char(1),
id int
)
INSERT INTO @.tempTable VALUES ('A', 1)
INSERT INTO @.tempTable VALUES ('B', 2)
INSERT INTO @.tempTable VALUES ('C', 3)
SELECT * FROM @.tempTable WHERE letter IN
(Case 2
WHEN 1 THEN ('A')
WHEN 2 THEN ('B', 'C')
END)
If you try to run this code, it gives an error on the line that
contains the 'B', 'C' (incorrect syntax near ',').
If you remove the C and just leave the two lines, one with A, one with
B, then it will work as expected.I can't make head or tail of what you are trying to do here (mostly because
of the 'Case 2' which will always try to run the B,C variant), but in any
case, an IN list cannot be the result of a CASE expression.
Maybe you meant something like this (wild guesses here):
DECLARE @.tinyint TINYINT;
SET @.tinyint = 2;
SELECT * FROM @.temptable
WHERE @.tinyint = CASE
WHEN letter = 'A' THEN 1
WHEN letter IN ('B','C') THEN2
END
The important thing to remember is that CASE is not for control of flow, it
is an expression that returns exactly one datatype, and all possible
outcomes must be able to yield the same datatype (or NULL).
Maybe you could try with a slightly more realistic example of what you are
really trying to accomplish, with real sample data and real desired results.
I can't deduce anything from A,B,C.
A
<MatthewSumpter@.gmail.com> wrote in message
news:1167774294.707435.113300@.42g2000cwt.googlegroups.com...
>I am trying to run a query that filters using an IN statment, but the
> IN statement needs to be dynamically generated based upon some
> criteria. Here is my example:
> DECLARE @.tempTable TABLE
> (
> letter char(1),
> id int
> )
> INSERT INTO @.tempTable VALUES ('A', 1)
> INSERT INTO @.tempTable VALUES ('B', 2)
> INSERT INTO @.tempTable VALUES ('C', 3)
> SELECT * FROM @.tempTable WHERE letter IN
> (Case 2
> WHEN 1 THEN ('A')
> WHEN 2 THEN ('B', 'C')
> END)
>
> If you try to run this code, it gives an error on the line that
> contains the 'B', 'C' (incorrect syntax near ',').
> If you remove the C and just leave the two lines, one with A, one with
> B, then it will work as expected.
>|||OK,
Sorry that my example isn't the easiest to understand. I was actually
just trying to make it more readable. If it's true that the CASE
expression cannot return more than one value (such as an IN list), then
I may need to take another approach, but let me at least give you a
better example.
Let's say I have a table with products in it. Each product has a
category #.
Categories:
1 Shoes
2 Pants
3 Shirts
4 TVs
5 DVD Players
6 Xboxes
Now I want to do a select statement based upon a category type passed
into the procedure @.CategoryType. When @.CategoryType is "electronics",
I want to return all products with category numbers 4, 5, or 6.
Likewise, if "clothing" is passed in, I want to return all products
with 1, 2, 3.
SELECT * FROM Products WHERE CategoryID IN
(CASE @.CategoryType
WHEN "electronics" THEN (4,5,6)
WHEN "clothing" THEN (1,2,3)
END)
Hopefully, this makes more sense.
Thanks,
Matthew
Aaron Bertrand [SQL Server MVP] wrote:
> I can't make head or tail of what you are trying to do here (mostly because
> of the 'Case 2' which will always try to run the B,C variant), but in any
> case, an IN list cannot be the result of a CASE expression.
> Maybe you meant something like this (wild guesses here):
> DECLARE @.tinyint TINYINT;
> SET @.tinyint = 2;
> SELECT * FROM @.temptable
> WHERE @.tinyint = CASE
> WHEN letter = 'A' THEN 1
> WHEN letter IN ('B','C') THEN2
> END
> The important thing to remember is that CASE is not for control of flow, it
> is an expression that returns exactly one datatype, and all possible
> outcomes must be able to yield the same datatype (or NULL).
> Maybe you could try with a slightly more realistic example of what you are
> really trying to accomplish, with real sample data and real desired results.
> I can't deduce anything from A,B,C.
> A
>
> <MatthewSumpter@.gmail.com> wrote in message
> news:1167774294.707435.113300@.42g2000cwt.googlegroups.com...
> >I am trying to run a query that filters using an IN statment, but the
> > IN statement needs to be dynamically generated based upon some
> > criteria. Here is my example:
> >
> > DECLARE @.tempTable TABLE
> > (
> > letter char(1),
> > id int
> > )
> >
> > INSERT INTO @.tempTable VALUES ('A', 1)
> > INSERT INTO @.tempTable VALUES ('B', 2)
> > INSERT INTO @.tempTable VALUES ('C', 3)
> >
> > SELECT * FROM @.tempTable WHERE letter IN
> > (Case 2
> > WHEN 1 THEN ('A')
> > WHEN 2 THEN ('B', 'C')
> > END)
> >
> >
> > If you try to run this code, it gives an error on the line that
> > contains the 'B', 'C' (incorrect syntax near ',').
> >
> > If you remove the C and just leave the two lines, one with A, one with
> > B, then it will work as expected.
> >|||On 3 Jan 2007 06:50:11 -0800, Loganx80 wrote:
>OK,
>Sorry that my example isn't the easiest to understand. I was actually
>just trying to make it more readable. If it's true that the CASE
>expression cannot return more than one value (such as an IN list), then
>I may need to take another approach, but let me at least give you a
>better example.
>Let's say I have a table with products in it. Each product has a
>category #.
>Categories:
>1 Shoes
>2 Pants
>3 Shirts
>4 TVs
>5 DVD Players
>6 Xboxes
>Now I want to do a select statement based upon a category type passed
>into the procedure @.CategoryType. When @.CategoryType is "electronics",
>I want to return all products with category numbers 4, 5, or 6.
>Likewise, if "clothing" is passed in, I want to return all products
>with 1, 2, 3.
>SELECT * FROM Products WHERE CategoryID IN
> (CASE @.CategoryType
> WHEN "electronics" THEN (4,5,6)
> WHEN "clothing" THEN (1,2,3)
> END)
>
>Hopefully, this makes more sense.
Hi Matthew,
Best way to do this is to add a categories table with a CategoryID and a
CategoryType column. That way, you can add products (and categories!)
without having to change any queries. I have always hated hard-coded
magic values.
But if you do want to hard-code the values, try something like this
SELECT Col1, Col2, ... -- Never use SELECT * !!!
FROM Products
WHERE (@.CategoryType = 'electronics' AND CategoryID IN (4, 5, 6))
OR (@.CategoryType = 'clothing' AND CategoryID IN (1, 2, 3));
--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis

How can wrap a case statement around us

I would like to maybe wrap a case statement around the following so that I
can set any results that come back as NULL to 0 (the performance of updating
afterwards is horrible)
update STAGE_PHX_FACT_POLICY
set STAGE_PHX_FACT_POLICY.fire_fee_if = whdata1.dbo.premium_detail.fee,
STAGE_PHX_FACT_POLICY.fire_fee_written =
whdata1.dbo.premium_detail.billed_premium
from whdata1.dbo.premium_detail
inner join whdata1.dbo.lob_xref
on whdata1.dbo.premium_detail.premium_lob = whdata1.dbo.lob_xref.premium_lob
where whdata1.dbo.lob_xref.a_lob = '6'
and whdata1.dbo.premium_detail.policy_number =
STAGE_PHX_FACT_POLICY.policy_number
and whdata1.dbo.premium_detail.policy_date_time =
STAGE_PHX_FACT_POLICY.policy_date_time
Thanks you!>> ...around the following so that I can set any results that come back as
Lookup COALESCE or ISNULL function in SQL Server Books Online
Anith|||"Patrice" <Patrice@.discussions.microsoft.com> wrote in message
news:3B52A763-5C4B-4030-ACDF-7661406D5149@.microsoft.com...
>I would like to maybe wrap a case statement around the following so that I
> can set any results that come back as NULL to 0 (the performance of
> updating
> afterwards is horrible)
>
> update STAGE_PHX_FACT_POLICY
> set STAGE_PHX_FACT_POLICY.fire_fee_if = whdata1.dbo.premium_detail.fee,
> STAGE_PHX_FACT_POLICY.fire_fee_written =
> whdata1.dbo.premium_detail.billed_premium
> from whdata1.dbo.premium_detail
> inner join whdata1.dbo.lob_xref
> on whdata1.dbo.premium_detail.premium_lob =
> whdata1.dbo.lob_xref.premium_lob
> where whdata1.dbo.lob_xref.a_lob = '6'
> and whdata1.dbo.premium_detail.policy_number =
> STAGE_PHX_FACT_POLICY.policy_number
> and whdata1.dbo.premium_detail.policy_date_time =
> STAGE_PHX_FACT_POLICY.policy_date_time
You can use COALESCE or ISNULL to do this in a much simpler way. As you
didn't specify what needed updating, I'll take a guess that it's both
values:
update STAGE_PHX_FACT_POLICY
set STAGE_PHX_FACT_POLICY.fire_fee_if =
COALESCE(whdata1.dbo.premium_detail.fee,0) ,
STAGE_PHX_FACT_POLICY.fire_fee_written =
COALESCE(whdata1.dbo.premium_detail.billed_premium,0)
from whdata1.dbo.premium_detail
inner join whdata1.dbo.lob_xref
on whdata1.dbo.premium_detail.premium_lob = whdata1.dbo.lob_xref.premium_lob
where whdata1.dbo.lob_xref.a_lob = '6'
and whdata1.dbo.premium_detail.policy_number =
STAGE_PHX_FACT_POLICY.policy_number
and whdata1.dbo.premium_detail.policy_date_time =
STAGE_PHX_FACT_POLICY.policy_date_time
Dan

Monday, March 12, 2012

How can we improve the cover rate of the model?

Hi, all here, I found that in my case when I trained the data mining models, the model cover rate is very low (in my case, the train data set has 82 rows but the case occuring in the models I trained is only 25). How can I improve the cover rate to improve the quality of the models? (if it is possible in SQL Server 2005) I am using SQL Server 2005.

Cheers.

Please explain what you mean by "cover rate" and what you are trying to accomplish. 82 rows is a pretty small data set in general, especially if you hae many attributes.|||

Hi, yes. my training data set is quite small which is some university marks data for analysis.

my inputs for the data set are like: mark1, mark 2, marker1, marker2, then the output which i wanna predict is the agreed mark based on mark 1 and mark2 marked by marker1 and marker2 respectively..

In order to make the classification task easily I have discretized the continous mark to be categorical values.

In my data analysis case, the "cover rate" I mean is the cases covered by the mining model. Cos the training data set actually got 82 rows but the mining model just covered 25 cases of it.

Hope this explanation is clear for your help.

Thanks a lot.

|||Do you mean it accurately classified 25 cases?|||

Hi, Jamie, the number is what all the models covered in the trainings. Like I have 82 rows in the trainning set, for example, clustering model only grouped 25 cases (rows) into clusters.

Thanks a lot.

|||I'm not sure what's going on here - I think what you are saying is that the cluster support of all clusters when added together is only 25 when it should be 82. They should all be accounted for. You can always go to the prediction query tab and do a prediction query for Cluster() against your training data. You may also want to check the cluster probability as well. If the cluster probability is something very close to 1/# clusters, then it's likely the clusters aren't very strong. This isn't unexpected for such a small data set, but I'm not sure why you're only getting 25 altogether.|||

Hi, Jamie, is it that the model wont cover all the records during its training process?

Thanks a lot

|||No - it covers all of the data. If you can post the 82 rows we can take a look at it here.|||

Hi, Jamie, below is my training data for the mining models building.

.........................................................................................................................................

mark1,mark2,Agreed,marker1,marker2,difference
55,55,55,TC,GR,0
66,69,68,CM,JQ,3
38,37,38,JT,JQ,1
52,57,57,ST,GR,5
64,60,63,JWh,GR,4
54,54,54,BW,JW,0
65,69,67,CM,JQ,4
68,68,68,JWh,MW,0
76,68,72,CM,JWh,8
48,47,48,CL,GR,1
68,62,64,AL,JWh,6
43,40,43,BW,Rdu,3
64,,64,MW,ST,
65,65,65,DG,MB,0
,,,GR,ST,
64,,61,CM,DG,
55,56,56,CM,TC,1
67,61,65,DG,CM,6
54,54,54,JM,CL,0
46,46,46,GR,BS,0
68,72,68,JWh,CM,4
60,60,60,BW,BS,0
65,65,65,DG,GR,0
57,,57,CH,DG,
58,55,58,CS,JT,3
51,51,51,BS,EC,0
,64,65,MW,TC,
66,70,67,DG,RC,4
,,,DG,CM,
66,57,64,JWh,AL,9
77,,74,CM,DG,
54,56,55,MW,TC,2
61,,57,JQ,JT,
61,61,61,DG,CH,0
68,68,68,CH,JM,0
61,66,61,CH,RC,5
68,68,68,BS,CS,0
62,63,63,DG,CH,1
62,63,63,TC,DG,1
63,58,60,JQ,CM,5
76,70,74,JWh,TC,6
68,68,68,CS,BS,0
60,56,58,CM,JWh,4
66,64,65,JW,BW,2
63,,64,TC,DG,
58,,58,RD,DG,
64,72,68,TC,MH,8
72,,72,CH,DG,
66,60,66,GR,RC,6
58,58,58,BSm,GM,0
51,49,50,GR,CM,2
62,,62,BW,CH,
53,50,50,TC,GR,3
,74,74,JWh,MW,
61,60.5,61,JT,CS,0.5
62,63,63,DG,CH,1
58,58,58,BS,JM,0
64,66,66,JT,BS,2
63,60,62,JWh,TC,3
55,,55,MB,DG,
72,,72,BSm,SS,
62,67,64,RD,GM,5
71,67,70,GR,CM,4
62,66,62,CS,CM,4
,68,52,DF,MH,
65,65,65,GM,TC,0
55,56,56,EC,TC,1
66,,66,CH,DG,
70,72,70,JM,CL,2
,,,BW,JT,
57,57,57,DG,CM,0
58,58,58,TC,GM,0
60,60,60,DG,RD,0
54,55,55,TC,CS,1
,64,67,MW,JWh,
60,60,60,DG,GR,0
78,68,72,JWh,MW,10
60,60,60,GR,BS,0
43,48,46,ST,SS,5
57,61,60,SS,ST,4
60,55,60,MW,DF,5
62,62,62,ST,MW,0

...............................................................................................................................

The first column is about the data attributes names.

Thanks a lot for that.

|||

Does you data have a key column? The algorithms need a unique key column to determine that each row is a case. The "Agreed" column has 25 distinct values, so it looks like that is what you are using for your key.

I think you need to add an additional "ID" column to uniquely identify each row.

|||

Hi, Jamie, thanks a lot. Got it done as your suggestion.

Yes, the problem is that the column I used as the key column is only with 25 distinct values which resulted in only 25 cases were covered by the training model.

Thanks a lot.

How can we handle terabyte of data?

Hi All
I have some questions to ask, in case some company have terabyte of data in the production server which online 24X7.
1)How can they backup database? Do they use backup database complete into disk? or Tape? How can they verify the backup? How frequent that needs?
2)How can they handle disaster recovery? Is Log shipping and Clustering is good enough?
3)In case need to change some stored procedures or trigger. Do they upload to test in DEV Boxes? In case DEV box have only 80 GB? What is the criteria that should be consider?
4)In case they have already tested in DEV box and want to implement in the online production, How can they minimize the problem if it does occur?
I am sorry to ask a lots of questions. If you can answers item by item or suggest the good resources, this will be the great for me.
Thanks you in advances,
James Jarupan
I'm hoping you can partition your data in the case below.
We did and utilized parititioned views heavily. Breaking apart tables/dbs
when they grew beyond 250 GB so instead of 1 TB DB there were 4 250 GB DBs.
So if 1 DB went down it could be restored in smaller timeframe than 1DB of
TB size. Besides you can backup much faster.
Later we got SAN solutions and size of DB ceased to be so much of an issue
for backup purposes.
Optimizing procs for production is always difficult in such cases, before
releasing the proc to live production box the DBA again performed the actual
execution plan and the estimated execution plan for optimization. You would
still need to follow the Dev- Test- Production box test methodology to
capture most issues.
"James Jarupan" <James@.vincosoft.com> wrote in message
news:5F71E190-F3ED-40E9-8DBF-EC1091D196F2@.microsoft.com...
> Hi All
> I have some questions to ask, in case some company have terabyte of data
in the production server which online 24X7.
> 1)How can they backup database? Do they use backup database complete into
disk? or Tape? How can they verify the backup? How frequent that needs?
> 2)How can they handle disaster recovery? Is Log shipping and Clustering is
good enough?
> 3)In case need to change some stored procedures or trigger. Do they upload
to test in DEV Boxes? In case DEV box have only 80 GB? What is the criteria
that should be consider?
> 4)In case they have already tested in DEV box and want to implement in the
online production, How can they minimize the problem if it does occur?
> I am sorry to ask a lots of questions. If you can answers item by item
or suggest the good resources, this will be the great for me.
> Thanks you in advances,
> James Jarupan
>
|||Thanks you so much.

How can we handle terabyte of data?

Hi All
I have some questions to ask, in case some company have terabyte of data in
the production server which online 24X7.
1)How can they backup database? Do they use backup database complete into di
sk? or Tape? How can they verify the backup? How frequent that needs?
2)How can they handle disaster recovery? Is Log shipping and Clustering is g
ood enough?
3)In case need to change some stored procedures or trigger. Do they upload t
o test in DEV Boxes? In case DEV box have only 80 GB? What is the criteria t
hat should be consider?
4)In case they have already tested in DEV box and want to implement in the o
nline production, How can they minimize the problem if it does occur?
I am sorry to ask a lots of questions. If you can answers item by item or su
ggest the good resources, this will be the great for me.
Thanks you in advances,
James JarupanI'm hoping you can partition your data in the case below.
We did and utilized parititioned views heavily. Breaking apart tables/dbs
when they grew beyond 250 GB so instead of 1 TB DB there were 4 250 GB DBs.
So if 1 DB went down it could be restored in smaller timeframe than 1DB of
TB size. Besides you can backup much faster.
Later we got SAN solutions and size of DB ceased to be so much of an issue
for backup purposes.
Optimizing procs for production is always difficult in such cases, before
releasing the proc to live production box the DBA again performed the actual
execution plan and the estimated execution plan for optimization. You would
still need to follow the Dev- Test- Production box test methodology to
capture most issues.
"James Jarupan" <James@.vincosoft.com> wrote in message
news:5F71E190-F3ED-40E9-8DBF-EC1091D196F2@.microsoft.com...
> Hi All
> I have some questions to ask, in case some company have terabyte of data
in the production server which online 24X7.
> 1)How can they backup database? Do they use backup database complete into
disk? or Tape? How can they verify the backup? How frequent that needs?
> 2)How can they handle disaster recovery? Is Log shipping and Clustering is
good enough?
> 3)In case need to change some stored procedures or trigger. Do they upload
to test in DEV Boxes? In case DEV box have only 80 GB? What is the criteria
that should be consider?
> 4)In case they have already tested in DEV box and want to implement in the
online production, How can they minimize the problem if it does occur?
> I am sorry to ask a lots of questions. If you can answers item by item
or suggest the good resources, this will be the great for me.
> Thanks you in advances,
> James Jarupan
>|||Thanks you so much.

How can we handle terabyte of data?

Hi Al
I have some questions to ask, in case some company have terabyte of data in the production server which online 24X7
1)How can they backup database? Do they use backup database complete into disk? or Tape? How can they verify the backup? How frequent that needs
2)How can they handle disaster recovery? Is Log shipping and Clustering is good enough
3)In case need to change some stored procedures or trigger. Do they upload to test in DEV Boxes? In case DEV box have only 80 GB? What is the criteria that should be consider?
4)In case they have already tested in DEV box and want to implement in the online production, How can they minimize the problem if it does occur
I am sorry to ask a lots of questions. If you can answers item by item or suggest the good resources, this will be the great for me
Thanks you in advances
James JarupaI'm hoping you can partition your data in the case below.
We did and utilized parititioned views heavily. Breaking apart tables/dbs
when they grew beyond 250 GB so instead of 1 TB DB there were 4 250 GB DBs.
So if 1 DB went down it could be restored in smaller timeframe than 1DB of
TB size. Besides you can backup much faster.
Later we got SAN solutions and size of DB ceased to be so much of an issue
for backup purposes.
Optimizing procs for production is always difficult in such cases, before
releasing the proc to live production box the DBA again performed the actual
execution plan and the estimated execution plan for optimization. You would
still need to follow the Dev- Test- Production box test methodology to
capture most issues.
"James Jarupan" <James@.vincosoft.com> wrote in message
news:5F71E190-F3ED-40E9-8DBF-EC1091D196F2@.microsoft.com...
> Hi All
> I have some questions to ask, in case some company have terabyte of data
in the production server which online 24X7.
> 1)How can they backup database? Do they use backup database complete into
disk? or Tape? How can they verify the backup? How frequent that needs?
> 2)How can they handle disaster recovery? Is Log shipping and Clustering is
good enough?
> 3)In case need to change some stored procedures or trigger. Do they upload
to test in DEV Boxes? In case DEV box have only 80 GB? What is the criteria
that should be consider?
> 4)In case they have already tested in DEV box and want to implement in the
online production, How can they minimize the problem if it does occur?
> I am sorry to ask a lots of questions. If you can answers item by item
or suggest the good resources, this will be the great for me.
> Thanks you in advances,
> James Jarupan
>

Sunday, February 19, 2012

How can I test for divide by zero without using CASE?

Since the query builder (not the query analyzer) in enterprise manager does
not support case statments, I was wondering if there's a way to structure
the following in a different way (without case statements) so that the query
builder works. I thought there might be a way to do soemthing with NULLIF
and/or COALESCE but I got stuck.
CASE WHEN x = 0 THEN 0 ELSE y/x END AS AvgCustBalance
Thanks,
Keith> Since the query builder (not the query analyzer) in enterprise manager
> does
> not support case statments, I was wondering if there's a way to structure
> the following in a different way (without case statements) so that the
> query
> builder works.
Sure, don't use the query builder. Why do you want to force yourself to use
a tricycle to commute to work, when there's a Ferrari in your driveway?|||> Since the query builder (not the query analyzer) in enterprise manager
> does
> not support case statments, I was wondering if there's a way to structure
> the following in a different way (without case statements) so that the
> query
> builder works. I thought there might be a way to do soemthing with NULLIF
> and/or COALESCE but I got stuck.
> CASE WHEN x = 0 THEN 0 ELSE y/x END AS AvgCustBalance
How about :
WHERE x <> 0
--
Peace & happy computing,
Mike Labosh, MCSD
"When you kill a man, you're a murderer.
Kill many, and you're a conqueror.
Kill them all and you're a god." -- Dave Mustane|||Well, that will leave rows out. I wonder if something like this will work:
SELECT COALESCE(y/NULLIF(x,0),0)
FROM
(SELECT x = 1,y=5
UNION ALL SELECT x=2,y=5
UNION ALL SELECT x=0,y=5) z
"Mike Labosh" <mlabosh@.hotmail.com> wrote in message
news:uDUnLsoyFHA.904@.tk2msftngp13.phx.gbl...
> How about :
> WHERE x <> 0
> --
> Peace & happy computing,
> Mike Labosh, MCSD
> "When you kill a man, you're a murderer.
> Kill many, and you're a conqueror.
> Kill them all and you're a god." -- Dave Mustane
>|||Could you tell me what tool you are referring to as a Ferrari?
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:ue40XqoyFHA.3700@.TK2MSFTNGP10.phx.gbl...
> Since the query builder (not the query analyzer) in enterprise manager
> does
> not support case statments, I was wondering if there's a way to structure
> the following in a different way (without case statements) so that the
> query
> builder works.
Sure, don't use the query builder. Why do you want to force yourself to use
a tricycle to commute to work, when there's a Ferrari in your driveway?|||If one is a todler, then it makes perfect sense. ;-)
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:ue40XqoyFHA.3700@.TK2MSFTNGP10.phx.gbl...
> Sure, don't use the query builder. Why do you want to force yourself to
> use a tricycle to commute to work, when there's a Ferrari in your
> driveway?
>|||Query Analyzer, or a host of third party tools. Enterprise Manager is
definitely not the place to write code, view data or manage objects.
"Keith G Hicks" <krh@.comcast.net> wrote in message
news:e3R06DpyFHA.2960@.tk2msftngp13.phx.gbl...
> Could you tell me what tool you are referring to as a Ferrari?
> "Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in
> message
> news:ue40XqoyFHA.3700@.TK2MSFTNGP10.phx.gbl...
> Sure, don't use the query builder. Why do you want to force yourself to
> use
> a tricycle to commute to work, when there's a Ferrari in your driveway?
>
>|||Keith,
Try (as test):
--test for /0 error without using case
CREATE TABLE YX
(Y INT NOT NULL,
X INT NOT NULL)
INSERT YX
VALUES(10,1)
INSERT YX
VALUES(10,0)
INSERT YX
VALUES(10,2)
SELECT Y,X,COALESCE(Y/NULLIF(X,0),0) AS 'Y/X'
FROM YX
HTH
Jerry
"Keith G Hicks" <krh@.comcast.net> wrote in message
news:exTFjnoyFHA.1028@.TK2MSFTNGP12.phx.gbl...
> Since the query builder (not the query analyzer) in enterprise manager
> does
> not support case statments, I was wondering if there's a way to structure
> the following in a different way (without case statements) so that the
> query
> builder works. I thought there might be a way to do soemthing with NULLIF
> and/or COALESCE but I got stuck.
> CASE WHEN x = 0 THEN 0 ELSE y/x END AS AvgCustBalance
> Thanks,
> Keith
>|||This is good, thanks. I didn't realize that 5/null = null. Guess that should
have been obvious.
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:uREka%23oyFHA.3812@.TK2MSFTNGP09.phx.gbl...
SELECT COALESCE(y/NULLIF(x,0),0)
FROM
(SELECT x = 1,y=5
UNION ALL SELECT x=2,y=5
UNION ALL SELECT x=0,y=5) z|||As far as I understand QA does not have a feature that lets you build
queries in a visual way like you can in EM. I'm a very visually oriented
person and prefer to work in that type of an environment when I can. I
generally use Database workbench for most of my SQL work and I'm very happy
with that. But the vsiual query builder is far from complete. If you don't
mind listing some of the "host of third party tools" I'd find that a bit
more helpful.
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:OsN1zGpyFHA.2076@.TK2MSFTNGP14.phx.gbl...
Query Analyzer, or a host of third party tools. Enterprise Manager is
definitely not the place to write code, view data or manage objects.
"Keith G Hicks" <krh@.comcast.net> wrote in message
news:e3R06DpyFHA.2960@.tk2msftngp13.phx.gbl...
> Could you tell me what tool you are referring to as a Ferrari?
> "Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in
> message
> news:ue40XqoyFHA.3700@.TK2MSFTNGP10.phx.gbl...
> Sure, don't use the query builder. Why do you want to force yourself to
> use
> a tricycle to commute to work, when there's a Ferrari in your driveway?
>
>