Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL server express update query

Posted on 2016-07-17
6
Medium Priority
?
57 Views
Last Modified: 2016-07-18
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
0
Comment
Question by:PeterBaileyUk
[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
  • 4
  • 2
6 Comments
 
LVL 35

Expert Comment

by:ste5an
ID: 41716351
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

0
 

Author Comment

by:PeterBaileyUk
ID: 41716354
It did have a word position field called [wordposition] its in the scan the EE.jpg
0
 

Author Comment

by:PeterBaileyUk
ID: 41716355
does that change the solution example now?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 35

Accepted Solution

by:
ste5an earned 2000 total points
ID: 41716363
Please, include table DDL and sample data INSERT statements as runnable T-SQL script to your posts.

Just use it as order criteria in the concat-subquery..

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
                    ORDER BY wordposition
                    FOR XML PATH('')
                  )) AS ConcatWordText
    FROM    Filtered O
    GROUP BY O.SentenceID;

Open in new window


p.s. a question about coding (text) and a image. Doesn't ring that a bell? Do you really think that we open an image and copy then your code manually?
0
 

Author Comment

by:PeterBaileyUk
ID: 41716364
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.
0
 

Author Closing Comment

by:PeterBaileyUk
ID: 41716365
thank you very much
0

Featured Post

Independent Software Vendors: 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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

604 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