USE [zm]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/** zm_marine_farm
**/
CREATE PROCEDURE [dbo].[zm_add_gathering_data] (
@param1 NVARCHAR(32),
@param2 NVARCHAR(32),
@param3 FLOAT,
@param4 FLOAT,
@param5 FLOAT
) AS
BEGIN
IF (SELECT COUNT(TABLE_NAME)
FROM INFORMATION_SCHEMA.TABLES
WHERE INFORMATION_SCHEMA.TABLES.TABLE_NAME=@param1) = 0
BEGIN
EXEC('CREATE TABLE [dbo].[' + @param1 + '] (
[gather_time] [datetime] NOT NULL,
[device_node_id] [nvarchar](16) NOT NULL,
[water_temperature] [float] NULL,
[demand_oxygens] [float] NULL,
[salinity] [float] NULL)')
END
EXEC('INSERT INTO [dbo].[' + @param1 + '] (
[gather_time] ,
[device_node_id] ,
[water_temperature],
[demand_oxygens] ,
[salinity] )
VALUES (GETDATE(), '''
+ @param2 + ''','
+ @param3 + ','
+ @param4 + ','
+ @param5 + ')' )
END