Solved

SQL Cursor - How to concatenate a value

Posted on 2013-01-16
2
366 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 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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