![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi all, I am completely newbie at stored procedures, and I do need to do something that may be simple, but I don't know how to do. I am building a query inside a varchar variable, like this: DECLARE @i INTEGER DECLARE @s VARCHAR(255) SELECT @i = 0 WHILE @i < 3 BEGIN IF @i = 0 SELECT @s = @s + 'SELECT ' + CONVERT(VARCHAR, @i) ELSE SELECT @s = @s + ' UNION SELECT ' + CONVERT(VARCHAR, @i) SELECT @i = @i + 1 END And after that @s will be like... SELECT 1 UNION SELECT 2 UNION SELECT 3 ... and I want to run the select that is the value of @s. This could be something like EXECUTE_QUERY @s Does the command with this functionality really exists? Thanks in advance, Rafael Cotta |
#3
| |||
| |||
|
|
Hi all, I am completely newbie at stored procedures, and I do need to do something that may be simple, but I don't know how to do. I am building a query inside a varchar variable, like this: DECLARE @i INTEGER DECLARE @s VARCHAR(255) SELECT @i = 0 WHILE @i < 3 BEGIN IF @i = 0 SELECT @s = @s + 'SELECT ' + CONVERT(VARCHAR, @i) ELSE SELECT @s = @s + ' UNION SELECT ' + CONVERT(VARCHAR, @i) SELECT @i = @i + 1 END And after that @s will be like... SELECT 1 UNION SELECT 2 UNION SELECT 3 ... and I want to run the select that is the value of @s. This could be something like EXECUTE_QUERY @s Does the command with this functionality really exists? Thanks in advance, Rafael Cotta |
![]() |
| Thread Tools | |
| Display Modes | |
| |