Solved

Which method is better for performance?

Posted on 2009-04-02
10
228 Views
Last Modified: 2012-05-06
I have a identity field that holds order numbers.
I have another table that holds company code.

I concat company code + order number . So I have XYZ1234 or ABC56879
All fine. Now, user wants to search by entering ABC56879.

My options:
 1. Have a function to parse out ABC and use 56879 and search on that identity column.
 2. Create a new column. Concat company code + identity field. Use this new column to search.

which one is better/faster?
0
Comment
Question by:Camillia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24055847
2. can be achieved easily with a computed column, and can even be indexed.
sounds like it's exactly what you are looking for.
0
 
LVL 7

Author Comment

by:Camillia
ID: 24055937
cant use computed column. To concat CompanyCode + OrderNumber, i have to join 2 tables.
Been researching this all day :(

 so, go with #2 , new column, not a function?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24056750
>cant use computed column.
yes, you can. with "computed column" I don't mean "computed inside a query", but a column in the table:

ALTER TABLE yourtable ADD COLUMN CombinedOrder = Company_Code + CAST(order_number as varchar(30))

Open in new window

0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 7

Author Comment

by:Camillia
ID: 24058591
let me try it. This is like creating a new column. I will post back. Let me read about "computed column".
0
 
LVL 7

Author Comment

by:Camillia
ID: 24059620
That line gives me an error.

But here, i cant have a computed column on TWO tables. That "Company_Code" is coming from another table.
http://msdn.microsoft.com/en-us/library/ms191250.aspx
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24060034
I understand that the 2 fields are in 2 tables.
so, how is that supposed to work for the "search" ?
what is the link between the 2 tables?
0
 
LVL 7

Author Comment

by:Camillia
ID: 24060406
the link between the 2 tables is an ID.

 For the search, if user enters XYZ1234, i can do a select on the composite column to get the result..  select * from table having (code+number)

no? I've probably missed the boat totally on this..

I can go with a new column, and on insert, just concat code+number and dump the values there...
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24060539
last clarifications:
how to "split" the search value?
will it ALWAYS be 3 characters + some digits, or should be take all the characters for the company code and the digits for the number?
0
 
LVL 7

Author Comment

by:Camillia
ID: 24060663
any character for the company. I found this function to parse out the non-numeric and just spit out digits. From Scott Pletcher on this forum.
ALTER FUNCTION [dbo].[fn_strip_nonnumeric] (
    @string VARCHAR(1000)
)
RETURNS VARCHAR(1000)
AS
BEGIN
DECLARE @SiteCode INT
SET @SiteCode = PATINDEX('%[^0-9]%', @string)
WHILE @SiteCode > 0
BEGIN
    SET @string = LEFT(@string, @SiteCode - 1) + SUBSTRING(@string, @SiteCode + 1, 1000)
    SET @SiteCode = PATINDEX('%[^0-9]%', @string)
END --WHILE
RETURN @string
END 

Open in new window

0
 
LVL 7

Accepted Solution

by:
Camillia earned 0 total points
ID: 24076617
i didnt get an answer. I ended up creating a new column. In the stored proc, i concat the values and store in the new column.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MS SQL page split per second is high 19 138
SQL Server 2012 express 24 44
Database maintenance 36 136
Backing up Large SQL Server VM Best practice [using Veeam Backup] 8 69
There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question