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 7859767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:01:50+00:00 2026-06-02T22:01:50+00:00

I have created nested cursor which basically compares column values of one table To

  • 0

I have created nested cursor which basically compares column values of one table To column values of another and returns the closest match.

Contents of Tables are say :

(ColumnName and Values are as below)
Table A

**Names**
MandarinOrange
SweetApple
SourApple
AppleThatTasteslikeGrapes

Table B

**Names**
PlainOrange
SourOrange
Grapple
.
.
.

So the Cursor1 (outer cursor) takes each name from table1 and compares with all the names in Table2 and returns me the closest match.Cursor 2 (inner) is to retrieve the names in table 2

I am looking to see, if there is a way to acheive the same avaoiding using Cursors
(because it is too slow)

  • 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-02T22:01:52+00:00Added an answer on June 2, 2026 at 10:01 pm

    Avoid cursors is always a better practice and in your case, I think it’s also achievable. The key to it is the calculation you perform in order to evaluate the comparison result.

    One solution is to create a function takes two strings and return a 1/0 value as the comparison result. Then you can call the function as part of the SELECT statement and save the cursor iteration.

    Here’s an example for such a function:

    CREATE FUNCTION fn_Compare
    (
        @firstValue     varchar(50),
        @secondValue    varchar(50)
    )
    RETURNS bit
    AS
    BEGIN
        DECLARE @Result bit
        SET @Result = 0 --False by default
    
        --!Here goes your specific logic for comparing string!  
        IF @firstValue = @secondValue
            SET @Result = 1
    
        RETURN @Result
    
    END
    GO
    
    --Use it in a sentance
    SELECT dbo.fn_Compare('TEST', 'TEST') AS Match --True
    SELECT dbo.fn_Compare('TEST', 'TEST2') AS Match --False
    
    --Use it in a query
    SELECT 
        name,
        name,
        dbo.fn_Compare(name, name) AS Match
    FROM sysobjects
    WHERE 
        Type = 'u'
    
    --Cleanup
    DROP FUNCTION fn_Compare
    

    I hope this helps.

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

Sidebar

Related Questions

I want to have a nested table holding custom objects, by adding them one
I have a List object, with nested Tasks. I have created a page that
I'm working on a navigation control. I have nested lists which creates this: What
I have created a service which displays a status bar notification after certain time
I have created a very simple nested loop example and am struggling to write
So I have created a nested template (a map of vectors) using stanford's CS106
I have a Content model which has one or many Audio files which need
I have created this type: create or replace type PRODTABLE as table of PROD_OBJ;
I have created a nested list with drag/drop functionality. My issue is that I
How would I create a nested list, I currently have this public function getNav($cat,$subcat){

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.