Help required for a stored proc. Refer the stored proc given below.
The id_val table has columns
name nvarchar(25)
val1 int
val2 int
val3 int
val4 int
These columns can increase till val9, which will be handled programatically through a VB component.
The problem in the stored proc given below is that I can't
uncommnet the val5 to val9 statements in the Case structure.
The reason for this is the stored proc. won't compile, because the columns don't exist as of now, they will be added at any point of time.
I tried using dynamic SQL but to no avail, I can't use a local variable declared in the scope stored proc. don't work in Dynamic SQL.
Any soultions, suggestions are welcome.
Thanks,
Mukund.
CREATE PROCEDURE generateid
@inid nvarchar(25),
@loc_id int
AS
DECLARE @loc_val int, @id_val int, @final_id int, @SQL varchar(100)
select @id_val=
CASE @loc_id
WHEN 1 THEN val1
WHEN 2 THEN val2
WHEN 3 THEN val3
WHEN 4 THEN val4
/*WHEN 5 THEN val5
WHEN 6 THEN val6
WHEN 7 THEN val7
WHEN 8 THEN val8
WHEN 9 THEN val9 */
END
from id_val
where name = @inid
The id_val table has columns
name nvarchar(25)
val1 int
val2 int
val3 int
val4 int
These columns can increase till val9, which will be handled programatically through a VB component.
The problem in the stored proc given below is that I can't
uncommnet the val5 to val9 statements in the Case structure.
The reason for this is the stored proc. won't compile, because the columns don't exist as of now, they will be added at any point of time.
I tried using dynamic SQL but to no avail, I can't use a local variable declared in the scope stored proc. don't work in Dynamic SQL.
Any soultions, suggestions are welcome.
Thanks,
Mukund.
CREATE PROCEDURE generateid
@inid nvarchar(25),
@loc_id int
AS
DECLARE @loc_val int, @id_val int, @final_id int, @SQL varchar(100)
select @id_val=
CASE @loc_id
WHEN 1 THEN val1
WHEN 2 THEN val2
WHEN 3 THEN val3
WHEN 4 THEN val4
/*WHEN 5 THEN val5
WHEN 6 THEN val6
WHEN 7 THEN val7
WHEN 8 THEN val8
WHEN 9 THEN val9 */
END
from id_val
where name = @inid