Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8786129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:32:18+00:00 2026-06-13T21:32:18+00:00

I have a written a query in which I create a string and take

  • 0

I have a written a query in which I create a string and take distinct values from the table based on conditions.

The table has some 5000 rows. This query takes almost 20 second to execute.

I believe that the string comparisons have made the query so slow. But I wonder what are my alternatives.

Query:

select distinct
   Convert(nvarchar, p1.trafficSerial) +' ('+  p1.sourceTraffic + ' - ' + p1.sinkTraffic + ' )' as traffic
from 
   portList as p1
inner join 
   portList as p2 ON p1.pmId = p2.sinkId
                  AND P1.trafficSerial IS NOT NULL 
                  AND (p1.trafficSerial = p2.trafficSerial) 
                  AND (P1.sourceTraffic = P2.sourceTraffic) 
                  AND (P1.sinkTraffic = P2.sinkTraffic)
where 
   p1.siteCodeID = @SiteId
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:32:19+00:00Added an answer on June 13, 2026 at 9:32 pm

    One option is to create a computed column and create an index on that

    This article discusses it http://blog.sqlauthority.com/2010/08/22/sql-server-computed-columns-index-and-performance/

    ALTER TABLE dbo.portList ADD
    traffic AS Convert(nvarchar,trafficSerial) +' ('+  sourceTraffic + ' - ' + sinkTraffic + ' )' PERSISTED
    GO
    
    CREATE NONCLUSTERED INDEX IX_portList_traffic
    ON dbo.portList  (traffic)
    GO
    
    select distinct traffic from dbo.portList 
    

    You should also make sure each of the columns in your join relationships have indexes on them:

    p1.trafficSerial & p2.trafficSerial
    P1.sourceTraffic & P2.sourceTraffic
    P1.sinkTraffic & P2.sinkTraffic
    

    and the column for your filter: p1.siteCodeID

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a query to find similar ids based on tags from a
I have written a DB2 query to do the following: Create a temp table
i have written insert query for my application to create new user with password,
I have written this query for retrieving data from mysql as below select FeedbackCode,EMailID,FeedbackDetail,
I have written a query in Sql server 2008. select select * from program
Context: Windows7, VBScript, ADODB and ADOX. I have written some VBScript code which creates
I have a string in linq which is loaded from xml, that attribute or
Below is stored procedure I have written which used nested cursor. create or replace
I have a function I've written that was initially supposed to take a string
I have a table which defines a child-parent relationship between nodes: CREATE TABLE node

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.