Avatar of PeterBaileyUk
PeterBaileyUk
 asked on

SQL server express update query

I have a query just to show 1 client code as a demo. I would like to update the [strshort] column to be populated like this:

any words not in the TblWordTags to be used in the creation of the short string:

here
word 1= "A3"
word 2 ignore as it is in TblWordTags
Word 3 = Sport

query must update StrShort in this example to A3 + chr32() + Sport

The order of the rebuilt short string goes in same order just minus the words we dont want.

I am in a vb.net windows application pulling data from Sql server db Dictionary. I am not sure how to create this query, can it be done soley in sql server and then run as a stored procedure or do I need to pull the data in and create a function to do it?
. I only need to do the operation for clientcodes that have tagged words in TblTagWords.
EE.JPG
Microsoft SQL Server

Avatar of undefined
Last Comment
PeterBaileyUk

8/22/2022 - Mon
ste5an

First of all: You're talking about order of words, but your sample does not provide information about this order. Much worse it does not even has an criteria, which can be used for ordering.

So you may use something like

DECLARE @StopWords TABLE
    (
      StopWordText NVARCHAR(255) NOT NULL
                                 PRIMARY KEY
    );

INSERT  INTO @StopWords
VALUES  ( N'and' );

DECLARE @Words TABLE
    (
      WordText NVARCHAR(255) NOT NULL ,
      SentenceID INT NOT NULL
    );

INSERT  INTO @Words
VALUES  ( N'A3', 1 ),
        ( N'and', 1 ),
        ( N'Sport', 1 ),
        ( N'Cookies', 2 ),
        ( N'and', 2 ),
        ( N'Tea', 2 );

WITH    Filtered
          AS ( SELECT   W.WordText ,
                        W.SentenceID
               FROM     @Words W
                        LEFT JOIN @StopWords SW ON W.WordText = SW.StopWordText
               WHERE    SW.StopWordText IS NULL
             )
    SELECT  O.SentenceID ,
            RTRIM(( SELECT  I.WordText + ' '
                    FROM    Filtered I
                    WHERE   I.SentenceID = O.SentenceID
                  FOR
                    XML PATH('')
                  )) AS ConcatWordText
    FROM    Filtered O
    GROUP BY O.SentenceID;

Open in new window

PeterBaileyUk

ASKER
It did have a word position field called [wordposition] its in the scan the EE.jpg
PeterBaileyUk

ASKER
does that change the solution example now?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
ste5an

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
PeterBaileyUk

ASKER
apologies I am a beginner at the sql server stuff and berating me publicly seems a tad unkind but well that's in-experience for you. The image was there For info and not meant too offend. I will endeavor in future to add the items you said.
PeterBaileyUk

ASKER
thank you very much