Solved

SQL Cursor - How to concatenate a value

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Complex SQL script 1 31
powershell and sql server - alerting 7 77
How to pass a parameter to limit the colums returned in Stored Procedure SQL 2016 2 29
SQL Exceptions 3 37
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, …
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

911 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

17 Experts available now in Live!

Get 1:1 Help Now