Showing posts with label index. Show all posts
Showing posts with label index. Show all posts

Friday, March 30, 2012

How to make this expression SARGable

a quick qn : i have this filter in my where clause and i know this is not
sargable. how can i make it one? ( i want to make use of a covered index on
prodid column)
any help is appreciated
SELECT ... FROM ...
WHERE (left(prodid,11) like replace(left(@.pegid,11), '*', '%'))
col/var datatype and width are :
prodid char(14)
@.pegid varchar(11)Maybe something like this (untested)
declare @.SargID varchar (12)
select SargID = replace(left(@.pegid,11), '*', '%') +'%'
SELECT ... FROM ...
WHERE prodid like SargID
http://sqlservercode.blogspot.com/atom.xml
"paraa" wrote:

> a quick qn : i have this filter in my where clause and i know this is not
> sargable. how can i make it one? ( i want to make use of a covered index o
n
> prodid column)
> any help is appreciated
> SELECT ... FROM ...
> WHERE (left(prodid,11) like replace(left(@.pegid,11), '*', '%'))
> col/var datatype and width are :
> prodid char(14)
> @.pegid varchar(11)
>|||are you trying for something like this
SELECT * FROM EMPLOYEES WHERE prodid like '***********%'
--
Regards
R.D
--Knowledge gets doubled when shared
"paraa" wrote:

> a quick qn : i have this filter in my where clause and i know this is not
> sargable. how can i make it one? ( i want to make use of a covered index o
n
> prodid column)
> any help is appreciated
> SELECT ... FROM ...
> WHERE (left(prodid,11) like replace(left(@.pegid,11), '*', '%'))
> col/var datatype and width are :
> prodid char(14)
> @.pegid varchar(11)
>|||i'm trying to search product ids (prodid) in the database that match the use
r
entered argument in @.pegid which can contain wildcard *
"R.D" wrote:
> are you trying for something like this
> SELECT * FROM EMPLOYEES WHERE prodid like '***********%'
> --
> Regards
> R.D
> --Knowledge gets doubled when shared
>
> "paraa" wrote:
>|||"paraa" <paraa@.discussions.microsoft.com> escribi en el mensaje
news:6E02D64A-E654-4511-BC48-BC39FEF6D3B9@.microsoft.com...
> i'm trying to search product ids (prodid) in the database that match the
> user
> entered argument in @.pegid which can contain wildcard *
>
You cant do that, if you want to use a index the where must be some
like this:
where a like 'xxxx%'
The % must be in the last position.
The only solution if you want query like this 'xxx%xxx' it is to use
Full-Text indexes, lok in the BOL for it.
> "R.D" wrote:
>|||To add, this is true in SQL Server 2000. SQL Server 2005 is smarter in this
respect. It collects string summary statistics to improve cardinality
estimations for LIKE predicates with arbitrary wildcards. It collects
information about the frequency distribution of substrings for character
columns. As you mentioned, SQL Server 2000 typically considered using an
index when the LIKE pattern has a constant prefix (col LIKE 'const%'). SQL
Server 2005 can make selectivity estimations even when the pattern doesn't
have a constant prefix (col LIKE '%const%'). In some cases, it can use an
index scan followed by lookups instead of opting for a table scan to begin
with.
BG, SQL Server MVP
www.SolidQualityLearning.com
Join us for the SQL Server 2005 launch at the SQL W in Israel!
[url]http://www.microsoft.com/israel/sql/sqlw/default.mspx[/url]
"Tako" <mi@.correo.es> wrote in message
news:ulkWTuyyFHA.2540@.TK2MSFTNGP09.phx.gbl...
> "paraa" <paraa@.discussions.microsoft.com> escribi en el mensaje
> news:6E02D64A-E654-4511-BC48-BC39FEF6D3B9@.microsoft.com...
> You cant do that, if you want to use a index the where must be some
> like this:
> where a like 'xxxx%'
> The % must be in the last position.
> The only solution if you want query like this 'xxx%xxx' it is to use
> Full-Text indexes, lok in the BOL for it.
>
>|||thx a lot all for ur time and inputs...greatly appreciated.
"paraa" wrote:

> a quick qn : i have this filter in my where clause and i know this is not
> sargable. how can i make it one? ( i want to make use of a covered index o
n
> prodid column)
> any help is appreciated
> SELECT ... FROM ...
> WHERE (left(prodid,11) like replace(left(@.pegid,11), '*', '%'))
> col/var datatype and width are :
> prodid char(14)
> @.pegid varchar(11)
>|||Couldn't you do...
SELECT
pkID
, blah1
, blah2
FROM
tblSomething
WHERE
pkID IN ( select pkID from tblSomething WHERE <your-clause> )
It might return the records slower, but because it has searched on a list of
indexed keys it should be updatable?
"paraa" <paraa@.discussions.microsoft.com> wrote in message
news:8B46071E-60AF-45E9-A951-7D522F772A15@.microsoft.com...
> a quick qn : i have this filter in my where clause and i know this is not
> sargable. how can i make it one? ( i want to make use of a covered index
on
> prodid column)
> any help is appreciated
> SELECT ... FROM ...
> WHERE (left(prodid,11) like replace(left(@.pegid,11), '*', '%'))
> col/var datatype and width are :
> prodid char(14)
> @.pegid varchar(11)
>|||> where a like 'xxxx%'
> The % must be in the last position.
> The only solution if you want query like this 'xxx%xxx'
Actually, the index can be used for at least a *portion* of this plan, e.g.
identifying the rows that start with xxx ...

Wednesday, March 28, 2012

How to make SSRS BOL part of the VS Help

Is there a way to make SSRS BOL included in the help documentation avalable
from with in the VS IDE? For example, in the Help Index tab have SSRS BOL
one of the filter options in the Filtered by dropdown box and use that to
lookup SSRS issues from inside the VS IDE.
Thanks.
--
moondaddy@.nospam.nospamHi moondaddy,
Welcome to use MSDN Managed Newsgroup!
From your descriptions, I understood that you would like to get the
Reporting Services BOL direcly from VS IDE. If I have misunderstood your
concern, please feel free to point it out.
Based on my knowledge, we do not have these integration version of VS IDE
help or Reporting Services Help. You will have to open Reporting Services
Books Online separately.
Sincerely yours,
Michael Cheng
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=====================================================
This posting is provided "AS IS" with no warranties, and confers no rights.|||OK Thanks.
--
moondaddy@.nospam.nospam
"Michael Cheng [MSFT]" <v-mingqc@.online.microsoft.com> wrote in message
news:MrTabd8SFHA.2184@.TK2MSFTNGXA01.phx.gbl...
> Hi moondaddy,
> Welcome to use MSDN Managed Newsgroup!
> From your descriptions, I understood that you would like to get the
> Reporting Services BOL direcly from VS IDE. If I have misunderstood your
> concern, please feel free to point it out.
> Based on my knowledge, we do not have these integration version of VS IDE
> help or Reporting Services Help. You will have to open Reporting Services
> Books Online separately.
>
> Sincerely yours,
> Michael Cheng
> Microsoft Online Partner Support
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> =====================================================> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
>|||Hi Moondady,
You are welcome!
If you have any questions or concerns next time, don't hesitate to let me
know. We are always here to be of assistance!
Sincerely yours,
Michael Cheng
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=====================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Friday, February 24, 2012

How to know the order of entries in a table

For example some data has entered into a table in a random manner i.e the pk filed value is not in a serial fashion.Is there any table or index that holds the entries of rows into a particular table as entered .

i.e
'some_table' has data like this

3,entry3
2,entry2
4,entry4
1,entry1

I want some DB table or Index that holds data like this about above 'some_table'

row_id ... ... ...
1
2
3
4

here 1 refers to entry of the first column in 'some_table' i.e 3,entry3
and so on...Hi

Please reread my first post in here:
http://www.dbforums.com/showthread.php?t=1620041

There is no order. If you need to know the order that data was inserted then you need to set something up yourself - use an identity column or a timestamp with a GETDATE() default value. Note that the second option will result in "ties" if you insert sets of data.|||Thanks for your help...