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

  • Home
  • SEARCH
  • 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 7081665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:56:56+00:00 2026-05-28T06:56:56+00:00

I have got the following SQL statement (SQL Server): DECLARE @atr nvarchar(255), @con nvarchar(1000),

  • 0

I have got the following SQL statement (SQL Server):

DECLARE @atr nvarchar(255), @con nvarchar(1000), @func nvarchar(5);
SET @con='example'
SET @func=(SELECT FNCELEM FROM CNDSC WHERE NAME LIKE @con)
DECLARE Atr_Cursor CURSOR FOR
SELECT ATRBT FROM CNEA WHERE (ELEMS LIKE '%'+@func+'%' AND NOT ELEMS LIKE '%1' + @func   + '%');
OPEN Atr_Cursor;
FETCH NEXT FROM Atr_Cursor
INTO @atr;
WHILE @@FETCH_STATUS = 0
  BEGIN
    DECLARE @SQLString nvarchar(500);
    IF (SELECT COUNT(*) FROM CNEXTRA WHERE ATR LIKE ''+@atr+'' AND NAME LIKE  ''+@con+'')>0
    BEGIN
    SET @SQLString= N'SELECT NAME, ATR, CNVAL, INRDR FROM CNEXTRA WHERE ATR LIKE ''' + @atr + ''' AND NAME LIKE '''+@con+''';';
    END
    ELSE
    BEGIN
    SET @SQLString= N'SELECT '''+@con+''' AS NAME, '''+@atr+''' AS ATR, '''' AS CNVAL, '''' AS INRDR';
    END
    EXEC (@SQLString);
    FETCH NEXT FROM Atr_Cursor
    INTO @atr;
  END
CLOSE Atr_Cursor;
DEALLOCATE Atr_Cursor;

Obviously, this statement returns several results due to the loop. While trying to use this statement with my C# code, I can only get the result of the last loop (obviously too). So I tried to transer the results into a temporary table; that worked. But now I’ve got the problem that I am not able to build the “complement” of that statement, so that the results are written back into the table.

If it is possible to change the query, so that there are no more loops, I think building the complement of the query will be easier.

So in fact my question is: Is there a chance to change the statement, so that there are no more loops? How could that look like? And if it’s not possible, how will I have to build a complement of that statement?

Thanks a lot for any help.

  • 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-05-28T06:56:57+00:00Added an answer on May 28, 2026 at 6:56 am

    I think this query will do it.

    SELECT
        CNDSC.NAME,
        CNEA.ATRBT AS ATR,
        ISNULL(CNEXTRA.CNVAL,'') AS CNVAL,
        ISNULL(CNEXTRA.INRDR,'') AS INRDR
    FROM
        CNDSC
        INNER JOIN CNEA
            ON CNEA.ELEMS LIKE '%'+CAST(CNDSC.FNCELEM AS VARCHAR)+'%' AND
               NOT CNEA.ELEMS LIKE '%1'+CAST(CNDSC.FNCELEM AS VARCHAR)+'%'  
        LEFT OUTER JOIN CNEXTRA
            ON CNEXTRA.ATR LIKE CNEA.ATRBT AND
               CNEXTRA.NAME LIKE @con
    WHERE
        CNDSC.NAME LIKE @con;
    

    I used this schema. Please let me know which columns are wrong.

    CREATE TABLE CNDSC
        (NAME  VARCHAR(100), FNCELEM  VARCHAR(100));
    INSERT INTO CNDSC VALUES ('ONE','FUNC1');
    INSERT INTO CNDSC VALUES ('TWO','FUNC2');
    
    CREATE TABLE CNEA
        (ATRBT VARCHAR (100), ELEMS VARCHAR(100));
    INSERT INTO CNEA VALUES ('ATTRIBUTE1','FUNC1');
    INSERT INTO CNEA VALUES ('ATTRIBUTE2','FUNC2');
    
    CREATE TABLE CNEXTRA
        (ATR VARCHAR(100),
         NAME VARCHAR(100),
         CNVAL  VARCHAR(100),
         INRDR  VARCHAR(100));
    INSERT INTO CNEXTRA VALUES ('ATTRIBUTE1','ONE','CNVAL','INRDR');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got the following exception when try to select data from SQL Server
I have got the following problem since the server has safe mode turned on,
i have got a problem with my SQL Statement: Table structure: CREATE TABLE tags
I have got a SQL command like the following : SELECT * FROM temp1
I've got the following SQL statement that I am working on. I've trimmed it
I have got SQL Server database in which Table column name have spaces. For
I am using SQL Server 2008R2. I've got the following setup: -- Query #1
I have got the following code from here to read an Excel file using
I have got the following class structure, and have plenty of classes like C
I have got the following very simple code: function init() { var articleTabs =

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.