gb
2012-10-10 19:08:32 UTC
This is kind of discrimination query:
select distinct a.state_code from MyTable a
where a.state_code not in (
select distinct b.state_code from MyTable b
where b.report_date = CONVERT(char(10), GETDATE(), 126))
The external query:
select distinct a.state_code from MyTable a
returns the dataset:
state_code
CO
FL
IA
IL
KS
MN
MO
OH
TN
WI
The internal query:
select distinct b.state_code from MyTable b
where b.report_date = CONVERT(char(10), GETDATE(), 126)
returns:
state_code
CO
IA
IL
KS
MN
MO
OH
TN
WI
So I am expecting to get from original query the result:
state_code
FL
But it is to get stuck...
At the same time the query:
select distinct a.state_code from MyTable a
where a.state_code not in (
'CO',
'IA',
'IL',
'KS',
'MN',
'MO',
'OH',
'TN',
'WI'
)
returns the result very fast:
state_code
FL
Please help me to speed up the original query.
Thanks,
GB
select distinct a.state_code from MyTable a
where a.state_code not in (
select distinct b.state_code from MyTable b
where b.report_date = CONVERT(char(10), GETDATE(), 126))
The external query:
select distinct a.state_code from MyTable a
returns the dataset:
state_code
CO
FL
IA
IL
KS
MN
MO
OH
TN
WI
The internal query:
select distinct b.state_code from MyTable b
where b.report_date = CONVERT(char(10), GETDATE(), 126)
returns:
state_code
CO
IA
IL
KS
MN
MO
OH
TN
WI
So I am expecting to get from original query the result:
state_code
FL
But it is to get stuck...
At the same time the query:
select distinct a.state_code from MyTable a
where a.state_code not in (
'CO',
'IA',
'IL',
'KS',
'MN',
'MO',
'OH',
'TN',
'WI'
)
returns the result very fast:
state_code
FL
Please help me to speed up the original query.
Thanks,
GB