I have a SQL query like this :
ALTER PROCEDURE [dbo].[sp_dynamic_column_list](
@tahun varchar(4),
@bulan varchar(2),
@pks varchar(3))
AS
BEGIN
SET NOCOUNT ON;
DECLARE @totalrow int
DECLARE @inc int = 1
DECLARE @dynamictable NVARCHAR(MAX)
CREATE TABLE #temp
(
tanggal datetime,
)
-- query cari column dulu baru alter table temp diatas
SET @totalrow = dbo.fn_count_row_penerimaan(2014,11,40)
WHILE (@inc <= @totalrow)
BEGIN
ALTER TABLE #temp ADD @inc FLOAT
SET @inc = @inc + 1
END
INSERT INTO #temp
EXEC sp_get_list_penerimaan_pks2 @tahun, @bulan, @pks
SELECT * FROM #temp
DROP TABLE #temp
END
I got error like this:
[Err] 42000 - [SQL Server]Incorrect syntax near '@inc'.
I'm new to SQL Server and like to know the solution for this problem
Thanks in advance
sp_prefix for your stored procedures. Microsoft has reserved that prefix for its own use (see Naming Stored Procedures), and you do run the risk of a name clash sometime in the future. It's also bad for your stored procedure performance. It's best to just simply avoidsp_and use something else as a prefix - or no prefix at all!