Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 help

Author  Topic 

zez0
Starting Member

24 Posts

Posted - 2008-06-15 : 08:43:08
ALTER PROCEDURE dbo.result_count @name nvarchar ,@other nvarchar,@zezo nvarchar

/*
(
@parameter1 int = 5,
@parameter2 datatype OUTPUT
)
*/
AS
declare

@id_bill int
set @id_bill=(select max(@name)+1 from counter)


insert into counter (@zezo)
values (@id_bill)

i want to pass columen name as parameter put this give me wrong format


zezo

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-15 : 09:01:07
you need to use dynamic sql if you want to pass column name as a parameter.

ALTER PROCEDURE dbo.result_count @name nvarchar ,@other nvarchar,@zezo nvarchar

/*
(
@parameter1 int = 5,
@parameter2 datatype OUTPUT
)
*/
AS
declare @id_bill int,@sql varchar(8000)
set @id_bill=(select max(@name)+1 from counter)


set @sql='insert into counter (' + @zezo +')
values (' + @id_bill + ')'
exec (@sql)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-06-16 : 09:15:23
www.sommarskog.se/dynamic_sql.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -