Error: Declare scalar variable @oobe_oem_config

  • Hi guys,

    I am facing an issue with the below query. I am not sure what's wrong as I have already declared a variable and it's still giving me an error.

    USE [Test]

    GO

    ----------------------------- OOBEConfig --------------------------------------

    DECLARE @oobe_config_id int

    SET @oobe_config_id =isnull((select max([oobe_config_id]) from [dbo].[OOBEConfig]),0)+1

    SET IDENTITY_INSERT [dbo].[OOBEConfig] ON

    GO

    IF NOT EXISTS(SELECT 1 FROM [dbo].[OOBEConfig] WHERE [oobe_config_id] = @oobe_config_id OR ([aff_id] =1214 AND [lang_id]= 1 ) )

    INSERT INTO [dbo].[OOBEConfig]([oobe_config_id],[aff_id],[lang_id],[initial_wait_time_secs],[subsequent_wait_time_secs],[active_flag],[creation_dt],[change_dt],[changed_by])

    VALUES(@oobe_config_id,x,y,z,a,GETDATE(),GETDATE(),SUSER_SNAME())

    GO

    SET IDENTITY_INSERT [dbo].[OOBEConfig] OFF

    GO

    ----------------------------- OOBEOEMConfig --------------------------------------

    SET IDENTITY_INSERT [dbo].[OOBEOemConfig] ON

    GO

    IF NOT EXISTS(SELECT 1 FROM [dbo].[OOBEOemConfig] WHERE [oobe_oem_config_id] =@oobe_config_id)

    INSERT INTO [dbo].[OOBEOemConfig]([oobe_oem_config_id],[aff_id],[lang_id],[oem_service_type_id],[oem_service_input_data_format_id],[oem_service_output_data_format_id],[oem_service_input_params],[oem_service_url],[active_flag],[creation_dt],[change_dt],[changed_by],[oem_blob_encoding_type_id])

    VALUES(@oobe_config_id,a,b,c,d,e,f,'x',1,GETDATE(),GETDATE(),SUSER_SNAME(),2)

    GO

    SET IDENTITY_INSERT [dbo].[OOBEOemConfig] OFF

    GO

    Error: Declare scalar variable @oobe_oem_config

    I appreciate your help

    Regards,

    Faisal

  • You have to get rid of each GO in your code. The word GO is used by the SSMS as a batch separator. This means that you now have few different batches. The declare statement was written in the first one, but used in other batches where it doesn't exist.

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply