473,407 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Odd issue with LIKE operator and variable

Hoping someone can shed some light on this one, using MS SQL 2000,

I have a query like this;

Expand|Select|Wrap|Line Numbers
  1. Select T.TransactionRecordClass, T.ClassDetail from [remoteserver].otherdb.dbo.Data  T where T.TransactionRecordClass like '10000002%'

which will return around 10000 records in under 1 second.
My issue is that I need to make this part of a function, but as soon as I add parameters/variables ( see below ) , it goes from returning in under 1 second, to 11 minutes!!!

Expand|Select|Wrap|Line Numbers
  1. DECLARE @TRC_ID nvarchar (9)
  2. SET @TRC_ID = rtrim('10000002') + '%'
  3.  
  4. Select T.TransactionRecordClass, T.ClassDetail from [remoteserver].otherdb.dbo.Data  T where T.TransactionRecordClass like @TRC_ID

There is a non-clustered index on the 2 fields being returned , and about 77 million records in the table. I have attempted using Index hints, but found they are not allowed on remote queries..... So... any clues why this happens, and how to fix????

Thanks in advance for any help
Nov 1 '07 #1
2 2156
OK, found a solution...

The field type of T.TransactionRecordClass is "char", my variable is declared "nvarchar", but if I declare the variable as "char" then the query time is back to < 1 second

Hoping someone can shed some light on this one, using MS SQL 2000,

I have a query like this;

Expand|Select|Wrap|Line Numbers
  1. Select T.TransactionRecordClass, T.ClassDetail from [remoteserver].otherdb.dbo.Data  T where T.TransactionRecordClass like '10000002%'

which will return around 10000 records in under 1 second.
My issue is that I need to make this part of a function, but as soon as I add parameters/variables ( see below ) , it goes from returning in under 1 second, to 11 minutes!!!

Expand|Select|Wrap|Line Numbers
  1. DECLARE @TRC_ID nvarchar (9)
  2. SET @TRC_ID = rtrim('10000002') + '%'
  3.  
  4. Select T.TransactionRecordClass, T.ClassDetail from [remoteserver].otherdb.dbo.Data  T where T.TransactionRecordClass like @TRC_ID

There is a non-clustered index on the 2 fields being returned , and about 77 million records in the table. I have attempted using Index hints, but found they are not allowed on remote queries..... So... any clues why this happens, and how to fix????

Thanks in advance for any help
Nov 2 '07 #2
debasisdas
8,127 Expert 4TB
You never forget anything that you learn by intrest.
Nov 3 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Shane | last post by:
Hi, Thanks in advance for the help. I have been to many websites and tried several solutions to my problem, but have fixed part of it. It's time to come humbly to the newsgroups for help :-) ...
6
by: Ney André de Mello Zunino | last post by:
Hello. Searching around before posting this message revealed that the issue has been brought up a significant number of times (here are two related threads ). So /std::map<>/ does not provide...
17
by: Danny J. Lesandrini | last post by:
The following code works with a standard MDB to navigate to a particluar record (with a DAO recordset, of course) but it's giving me problems in an ADP I'm working on. Dim rs As ADODB.Recordset...
2
by: Eric Newton | last post by:
VB's more declarative nature of handling events is golden. I'm hoping C# will acquire this type of deal, in addition to the anonymous delegates. could do same as vb (actually would be easier to...
2
by: nayannovellus | last post by:
As per my knowledge i know that when a structure is defined, no memory is assigned to its members but when a variable of that structure is declared memory is allocated and also this allocation takes...
2
by: Paulo Matos | last post by:
Hi all, Guess I wish to do some parsing for a calculator which might include rational numbers. So I can have integers (sequence of digits possibly started by -) and rationals (two integers...
5
by: raylopez99 | last post by:
I need an example of a managed overloaded assignment operator for a reference class, so I can equate two classes A1 and A2, say called ARefClass, in this manner: A1=A2;. For some strange reason...
4
by: Christian Schmidt | last post by:
Hi all, I'm trying to implement a std::vector-like wrapper for IList. The hard part seems to be operator, because it returns an unmanaged reference. Probably I have to use pin_ptr to achieve this,...
4
by: George2 | last post by:
Hello everyone, My question is whether my understanding of the solution to type safe issue in CoCreateInstance is correct. There is type safe issue in CoCreateInstance, ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.