Hello chaps,
Any ideas why this wont work? Apparently varchar and unique identifier cannot be used with the + operator. New to dynamic SQL so havent a scooby...
Thanks in advance.
ALTER PROCEDURE dbo.AddPriceDataToExchangeTable
@symbolId uniqueidentifier,
@date smalldatetime,
@dateId int,
@priceOpen decimal(23,10),
@priceHigh decimal(23,10),
@priceLow decimal(23,10),
@priceClose decimal(23,10),
@volume bigint,
@openInterest int,
@exchange varchar(50)
AS
BEGIN
SET NOCOUNT ON;
Declare @SQL VarChar(1000)
SELECT @SQL = 'INSERT INTO' + @exchange + '(symbolId, dataDate , dateId, priceOpen ,priceHigh ,priceLow ,priceClose, volume, openInterest)'
SELECT @SQL = @SQL + ' VALUES (' + @symbolId + ',' + @date + ',' + @dateId + ',' + @priceOpen + ',' + @priceHigh + ',' + @priceLow + ',' + @priceClose + ',' + @volume + ',' + @openInterest + ')'
Exec (@SQL)
END
Any ideas why this wont work? Apparently varchar and unique identifier cannot be used with the + operator. New to dynamic SQL so havent a scooby...
Thanks in advance.
ALTER PROCEDURE dbo.AddPriceDataToExchangeTable
@symbolId uniqueidentifier,
@date smalldatetime,
@dateId int,
@priceOpen decimal(23,10),
@priceHigh decimal(23,10),
@priceLow decimal(23,10),
@priceClose decimal(23,10),
@volume bigint,
@openInterest int,
@exchange varchar(50)
AS
BEGIN
SET NOCOUNT ON;
Declare @SQL VarChar(1000)
SELECT @SQL = 'INSERT INTO' + @exchange + '(symbolId, dataDate , dateId, priceOpen ,priceHigh ,priceLow ,priceClose, volume, openInterest)'
SELECT @SQL = @SQL + ' VALUES (' + @symbolId + ',' + @date + ',' + @dateId + ',' + @priceOpen + ',' + @priceHigh + ',' + @priceLow + ',' + @priceClose + ',' + @volume + ',' + @openInterest + ')'
Exec (@SQL)
END