?
Solved

SQL Cursor - How to concatenate a value

Posted on 2013-01-16
2
Medium Priority
?
368 Views
Last Modified: 2013-01-20
I have a SQL Stored Procedure that validates a form.  One section of the validation needs to verify a keyword(s) was selected.  Depending on the users form there could be 3 to 25 keywords to confirm.

The idea is that @KEYWORDCATEGORY1 and @KEYWORDCATEGORY1_REQ need to increment to @KEYWORDCATEGORY2, @KEYWORDCATEGORY3 and @KEYWORDCATEGORY2_REQ, @KEYWORDCATEGORY3_REQ and so on.  

I am asuming I can do this by concatenating a variable  to @KEYWORDCATEGORY such as @KEYWORDCATEGORY3 + @VALUE or @KEYWORDCATEGORY+ @VALUE + '_REQ' where @VALUE woud start at 1.  Can this be done?



/*VERIFY KEYWORDS*/
DECLARE KEYWORDS_CRSR CURSOR STATIC LOCAL FOR
SELECT
           [KeywordId]
FROM
           [dbo].[TableName]
WHERE
           [User_Id] = @ID

OPEN KEYWORDS_CRSR

If @@CURSOR_ROWS > 0
BEGIN
     FETCH NEXT FROM KEYWORDS_CRSR INTO
                  @KEYWORDCATEGORY1

WHILE @@FETCH_STATUS = 0
BEGIN

    /*@KEYWORDCATEGORY1_REQ*/
    IF @KEYWORDCATEGORY1_REQ = 1
    BEGIN
             IF @KEYWORDCATEGORY1 IS NULL
             BEGIN
           SET @ACCEPTED = 0                  
                       SET @RESPONSE = @RESPONSE + '-A Keyword for Category l must be selected.<br />'
            END
             END

             FETCH NEXT FROM KEYWORDS_CRSR INTO
                          @KEYWORDCATEGORY1
END


THANKS!!
0
Comment
Question by:skinsfan99
[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
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 38782118
no, this cannot be done "like this"

but you could do this in a plain statement, without cursor, eventually.

can you clarify the data in the table, and what would the full output be?

thanks
0
 

Author Closing Comment

by:skinsfan99
ID: 38798147
Thank you!!
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

771 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