Solved

SQL Cursor - How to concatenate a value

Posted on 2013-01-16
2
357 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
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

757 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now