Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
alter  procedure test 
(
 @t1 varchar(50),
 @emp_id  varchar(15),
 @dept_id varchar(15),
 @emp_name varchar(50),
 @emp_status varchar(10)
)
 as
 begin
 
 DECLARE @SQL varchar(250)
 
 SELECT @SQL = 'insert into ' + @t1 + ' values ('+@emp_id+','+@dept_id+','+@emp_name+','+@emp_status+')'
 
 EXEC (@SQL)
    
 end 


exec test 'Tbl_101_Employee_Creation','E-00001','D-001','kiran','Active'

ERROR
Msg 207, Level 16, State 1, Line 1
Invalid column name 'E'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'D'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'kiran'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'Active'.


[edit]Code block added[/edit]
Posted
Updated 10-Dec-19 2:41am
v2

Alter procedure test 
(
@t1 varchar(50),
@emp_id varchar(15),
@dept_id varchar(15),
@emp_name varchar(50),
@emp_status varchar(10)
 
)
as
begin

DECLARE @SQL varchar(250)

SELECT @SQL = 'insert into ' + @t1 + ' values ('''+@emp_id+''','''+@dept_id+''','''+@emp_name+''','''+@emp_status+ ')'

print  (@SQL)

end 
 
Share this answer
 
you can use parameter freely without any single codes. like below..
alter procedure test
(
@t1 varchar(50),
@emp_id varchar(15),
@dept_id varchar(15),
@emp_name varchar(50),
@emp_status varchar(10)

)
as
begin

DECLARE @SQL varchar(250)

SELECT @SQL = 'insert into @t1 values (@emp_id,@dept_id,@emp_name,@emp_status)'

EXEC (@SQL)

end
 
Share this answer
 
Alter procedure test 
(
@t1 varchar(50),
@emp_id varchar(15),
@dept_id varchar(15),
@emp_name varchar(50),
@emp_status varchar(10)
 
)
as
begin
 
DECLARE @SQL varchar(250)
 
SELECT @SQL = 'insert into ' + @t1 + ' values ('''+@emp_id+''','''+@dept_id+''','''+@emp_name+''','''+@emp_status+ ''')'
 
EXEC  (@SQL)
 
end 
 
Share this answer
 
hi
I do also get the same error
from below code , could anyone please tell me what I am doing wrong ?
go
;with cte as(
select row_number()over(partition by date order by ID)ID,
Bussiness,Date, Value 
from mytable
)
SELECT *
FROM cte
PIVOT (
	MAX([Value])
	FOR Date IN ( [Nov-18],[Dec-18])
) AS pvt
 
Share this answer
 
Comments
CHill60 10-Dec-19 12:11pm    
The first thing you are doing wrong is posting a question as a solution to another member's post. Use the red "Ask a Question" link if you need help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900